https://issues.dlang.org/show_bug.cgi?id=13095
Issue ID: 13095 Summary: Someteims `struct` destructor is called if constructor throws Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: wrong-code Severity: major Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: verylonglogin....@gmail.com This code should run fine: --- import std.stdio; bool b = false; struct S { this(int) { throw new Exception(""); } ~this() { b = true; } } void main() { try S(0); catch(Exception) { } assert(!b); // fails } --- Also if a `Throwable` is thrown in destructor it is called recursively: --- import std.stdio; struct S { this(int) { throw new Exception(""); } ~this() { int p; asm { mov p, ESP; } writefln("~this, ESP: 0x%X", p); throw new Error(""); // calls `~this` } } void main() { try S(0); catch(Exception) writeln("catch Exception"); writeln("end main"); } --- <prints '~this, ESP: 0x...' until stack overflows> --- This is a major issue breaking RAII code. --