On Thursday, 12 February 2015 at 04:08:23 UTC, Jakob Ovrum wrote:
Is it possible to call the destructor or postblit constructor
directly
yes, they are available as obj.__dtor() and obj.__postblit();
But...
and will they correctly destruct/copy recursively
No.
extern(C)
@trusted void printf(const char*);
struct Child {
@safe ~this() { printf("child dtor\n"); }
}
struct Parent {
Child c;
@safe ~this() { printf("parent dtor\n"); }
}
void main() @safe {
Parent p;
p.__dtor();
}
parent dtor // this is the one from the p.__dtor
// note it did NOT run child dtor
parent dtor // the natural destruction from going out of scope
child dtor // ...which also calls the child
So you'd have to loop through all members in a custom destroy
function and call them yourself. Then attribute inference should
work.