[Issue 19602] New: Under some circumstances: throwing Error subclasses unwinds without invoking dtors

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 21 23:37:32 UTC 2019


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

          Issue ID: 19602
           Summary: Under some circumstances: throwing Error subclasses
                    unwinds without invoking dtors
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

Reproduction:

import std.stdio;
import std.traits;

struct S {
    this(int) { writeln("this(int)"); }
    ~this() { writeln("~this()"); }
}

void dtorsOk() {
    with(S(1)) { throw new Error("Err"); } // dtor call generated here
}

// inferred as "nothrow"
auto sneakyThrow() { throw new Error("Err"); }

void failsToDtor() {
    with(S(1)) sneakyThrow(); // dtor call skipped here, incorrectly
}

// And this is the reason:
static assert(hasFunctionAttributes!(sneakyThrow, "nothrow"));

unittest {
    writeln("dtorsOk:");
    try dtorsOk();
    catch(Error) {}

    writeln("failsToDtor:");
    try failsToDtor();
    catch(Error) {}
}

Prints:

dtorsOk:
this(int)
~this()
failsToDtor:
this(int)

--


More information about the Digitalmars-d-bugs mailing list