[Issue 20914] New: __xdtor bypasses function attributes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 9 16:41:47 UTC 2020


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

          Issue ID: 20914
           Summary: __xdtor bypasses function attributes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timon.gehr at gmx.ch

DMD 2.092.0:

import std.stdio, std.conv;
import core.stdc.stdlib;
extern(C++) class C{
    ~this()@nogc pure @safe nothrow{ }
}
extern(C++) class D:C{
    ~this(){ int[2] k; new int; writeln("impure"); k.ptr[1]=2; throw new
Exception(""); }
}
void main()@nogc pure nothrow{
    enum size=__traits(classInstanceSize,C);
    auto p = malloc(size)[0..size];
    C c = emplace!D(p);
    destroy(c); // calls D's destructor, but is annotated @nogc, pure and
nothrow
    free(p.ptr);
}

Not sure what's the best fix. Perhaps destructors of child classes should
inherit the base class destructor attributes. (That would also allow solving
issues with missing attributes on `destroy` for classes inheriting from
Object.)

--


More information about the Digitalmars-d-bugs mailing list