[Issue 11329] Struct dtor called for a struct with a failed ctor when struct is nested in a class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 24 20:27:50 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=11329

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Andrej Mitrovic from comment #0)
> but for some reason its dtor /is/
> called, however only in a situation when it's nested in a class.

The dtor is called from druntime during process finalization.
By inserting a print line at the end of main, you can confirm that.

void main()
{
    //// S dtor not called (ok, because its ctor failed)
    //assertThrown!Exception(S(1));

    // S dtor called even though S object was not 
    // properly initialized (ctor failed)
    assertThrown!Exception(new C());

    stderr.writeln("end main");
}

Prints:

$ dmd -run test
end main
S dtor -- _x: 1

--


More information about the Digitalmars-d-bugs mailing list