digitalmars.D.bugs - [Issue 15467] New: Compiler incorrectly flags a function as throwing
- via Digitalmars-d-bugs (51/51) Dec 22 2015 https://issues.dlang.org/show_bug.cgi?id=15467
https://issues.dlang.org/show_bug.cgi?id=15467 Issue ID: 15467 Summary: Compiler incorrectly flags a function as throwing an exception though it is caught Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: samjnaa gmail.com In relation to https://github.com/D-Programming-Language/phobos/pull/3751 I created the following code: mixin template basicExceptionCtors() { this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null) safe pure nothrow { super(msg, file, line, next); } this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__) safe pure nothrow { super(msg, file, line, next); } } pure nothrow safe unittest { class MeaCulpa: Exception { mixin basicExceptionCtors; } try throw new MeaCulpa("test"); catch (MeaCulpa e) { assert(e.msg == "test"); assert(e.file == __FILE__); assert(e.line == __LINE__ - 5); } } void main(){} Compiling the above I get the error: <src>(19): Error: <src>.__unittestL12_1.MeaCulpa is thrown but not caught <src>(12): Error: function '<src>.__unittestL12_1' is nothrow yet may throw Clearly the thrown exception is caught. As such the compiler incorrectly flags this as a violation of the `nothrow` declaration and should be fixed. --
Dec 22 2015