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.)
Comment #1 by timon.gehr — 2020-06-09T16:48:55Z
Also see issue 15246.
Comment #2 by robert.schadek — 2024-12-13T19:09:09Z