extern(C++) classes; dtor must go in vtable

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon May 21 21:53:51 UTC 2018


On Monday, May 21, 2018 14:33:44 Manu via Digitalmars-d wrote:
> How do virtual destructors work in normal D classes?

It is my understanding that destructors in D are never virtual but rather
that the runtime handles calling them correctly. IIRC, that relates to some
of the issues that make it so that you can't do stuff like call destroy in
@nogc code. And a quick test with __traits seems to indicate that
destructors are indeed not virtual:

    class C
    {
        void foo() {}
        ~this() {}
    }

    pragma(msg, __traits(isVirtualFunction, C.foo));
    pragma(msg, __traits(isVirtualFunction, C.__dtor));

    void main()
    {
    }

prints

true
false

- Jonathan M Davis



More information about the Digitalmars-d mailing list