www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - extern(C++) classes; dtor must go in vtable

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.

I have just done a bunch of work to make the dtor function semantics
match C++, and I think we can now try and fix the vtable issue.

I intend to try and populate the vtable for extern(C++) classes with
__xdtor at the first slot (and the second slot for posix needs some
special sauce too). That should allow for a class being destructed in
C++ code to work properly.

Then there's the issue where D code needs to make a virtual call to
the destructor when calling __xdtor... I tried that briefly and DMD
totally lost its mind when the destructor was virtual. I think theres
a lot of issues to work through making the destructor virtual.

I want to ask here for known issues/gotchas, or suspected hurdles from
the DMD devs? Confirm I'm on the right track...

There's a displeasing line of code:
https://github.com/dlang/dmd/blob/master/src/dmd/func.d#L3374
That's kinda in conflict with my whole effort, and it seems code
elsewhere also retains that assumption.

How do virtual destructors work in normal D classes?
May 21 2018