Bug 15467 – Compiler incorrectly flags a function as throwing an exception though it is caught

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-12-22T13:18:32Z
Last change time
2024-12-13T18:46:09Z
Keywords
EH
Assigned to
No Owner
Creator
Shriramana Sharma
Moved to GitHub: dmd#19079 →

Comments

Comment #0 by samjnaa — 2015-12-22T13:18:32Z
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.
Comment #1 by samjnaa — 2015-12-22T13:20:02Z
I forgot to mention that if the catch block catches an Exception instead of a MeaCulpa, then the compiler does not produce an error w.r.t. `nothrow`. Also, I'm using latest DMD 2.0.69.2.
Comment #2 by robert.schadek — 2024-12-13T18:46:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19079 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB