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

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon May 21 22:03:27 UTC 2018


On Monday, May 21, 2018 14:33:44 Manu via Digitalmars-d wrote:
> extern(C++) classes.
>
> Currently, we don't add destructors to the vtable... we suggest that
> users need to create some dummy virtual functions to fill those vtable
> slots so that the vtable layout otherwise matches the C++ class.
>
> This leaves us in a position where destruction doesn't work for
> polymorphic types.

How are you destroying any C++ types from D at all?

It was my understanding that you had to call C++ code to make that happen.
extern(C++) classes get constructed and destroyed/deleted in C++ code.
They're used in D code but aren't constructed or destroyed in D code. If
that's the case, then while having the virtual table line up properly
definitely matters, whether D treats the destructor as virtual is
irrelevant, because it's never called from D code.

I certainly have no problem with attempts to improve our integration with
C++, but it sounds to me like you're talking like you're currently calling
C++ destructors from D, and it's not working because they're not virtual,
when it's my understanding that doing that at all is unsupported - though my
understanding could certainly be outdated.

- Jonathan M Davis



More information about the Digitalmars-d mailing list