What is __dtor() supposed to do?
Cristi Cobzarenco
cristi.cobzarenco at gmail.com
Tue Jul 19 06:42:32 PDT 2011
This is somewhat in reference to a bug that I was having trouble with
(Issue 5667 - http://d.puremagic.com/issues/show_bug.cgi?id=5667).
Right now __dtor() simply represents the function defined between the
curly braces of ~this(), not the compiler generated function that
calls ~this() and the destructors of members in proper order. To
illustrate:
import std.stdio;
struct A { ~this() { writeln( "A.~this()"); } }
struct B {
~this() { writeln("B.~this()"); }
A member;
}
struct C {
A member;
}
void main() {
A a;
B b;
C c;
writeln( "using __dtor" );
a.__dtor(); // prints "A.~this()" as expected
b.__dtor(); // prints "B.~this()", but not "A.~this()
// c.__dtor(); // does not compile because there is no ~this() defined in C
writeln( "using TypeInfo_Struct.destroy" )
typeid(B).destroy(&a); // prints both A.~this() and B.~this()
typeid(C).destroy(&c); // compiles & prints A.~this();
writeln( "going out of scope" );
}
Basically my question is - is this the required behaviour? Or should
__dtor and destroy() do the same thing? If they should, then the bug I
mentioned is a compiler bug. Otherwise, the fix I proposed to druntime
would work.
---
Cristi Cobzarenco
BSc in Artificial Intelligence and Computer Science
University of Edinburgh
Profile: http://www.google.com/profiles/cristi.cobzarenco
More information about the Digitalmars-d
mailing list