From 4f2e16ed39763ab3eecb19b1d24961dfdc77a678 Mon Sep 17 00:00:00 2001 From: k-hara Date: Mon, 22 Jun 2015 21:40:16 +0900 Subject: [PATCH] fix Issue 14685 - Silent incorrect behavior with enforce and custom exception --- std/exception.d | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/std/exception.d b/std/exception.d index 28cce48eb72..0615490f229 100644 --- a/std/exception.d +++ b/std/exception.d @@ -394,7 +394,7 @@ private void bailOut(E : Throwable = Exception)(string file, size_t line, in cha } else { - static assert("Expected this(string, string, size_t) or this(string, size_t)" ~ + static assert(0, "Expected this(string, string, size_t) or this(string, size_t)" ~ " constructor for " ~ __traits(identifier, E)); } } @@ -509,6 +509,17 @@ deprecated unittest enforce!(S, __FILE__, __LINE__)(s, ""); } +unittest +{ + // Issue 14685 + + class E : Exception + { + this() { super("Not found"); } + } + static assert(!__traits(compiles, { enforce!E(false); })); +} + /++ If $(D !!value) is true, $(D value) is returned. Otherwise, $(D ex) is thrown.