[dmd-internals] Destructors are not virutal

Walter Bright walter at digitalmars.com
Mon Jan 23 22:56:49 PST 2012



On 1/23/2012 10:31 PM, Daniel Murphy wrote:
> > From the spec: There can be only one destructor per class, the
> destructor does not have any parameters, and has no attributes. It is
> always virtual.
>
> Yet in dmd for some reason, DtorDeclaration::isVirtual explicitly returns FALSE.
>
> As a result, the following prints "A\nB\nA"
> import std.stdio;
> class A { ~this() { writeln("A"); } }
> class B : A { ~this() { writeln("B"); } }
> void main()
> {
>    A a = new B();
>    a.__dtor();
> }
>
> It looks like a bug, but seems very deliberate.  Does anyone know why
> it's this way?
>
> Yes, I'm aware delete uses magic behind the scenes to get the correct result.
>

Because it's handled specially - not through the vtbl[].


More information about the dmd-internals mailing list