[dmd-internals] Destructors are not virutal

Daniel Murphy yebblies at gmail.com
Mon Jan 23 22:31:16 PST 2012


>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.


More information about the dmd-internals mailing list