Not sure if this is known, on macOS to get C++ ABI compatibility with a pure virtual class it seems you need to add an additional dummy call.
This is not required on Windows.
extern(C++) interface MyCPPCInterface
{
// Simulate C++ destructor so that the v-table layout is the same
void destroyThis();
// required not to crash...
version (OSX) void unknownCall(); // THIS IS SURPRISING
void otherMethod1();
[ Other methods... ]
}
Comment #1 by pro.mathias.lang — 2020-02-21T04:03:14Z
Works for me, using DMD 2.090.1 on OSX 10.15.2
Test code:
```
--- d.d
extern(C++) interface MyCPPCInterface
{
void otherMethod1();
}
extern(C++) MyCPPCInterface makeObject();
void main ()
{
MyCPPCInterface ex = makeObject();
ex.otherMethod1();
}
--- cpp.cpp
#include <cstdio>
class MyCPPCInterface
{
public:
virtual void otherMethod1();
};
void MyCPPCInterface::otherMethod1()
{
printf("Other method1\n");
}
MyCPPCInterface* makeObject()
{
return new MyCPPCInterface;
}
```
Compiled with:
```
$ g++ -c cpp.cpp
$ dmd cpp.o -L-lstdc++ -run d.d
```
No crash, and the printf is correctly called.
Given the D definition, I can only infer the C++ definition.
However, from what I can see, I think your issue had to do with the destructor: Two destructors are actually generated with the Itanium ABI, see:
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-components
> The entries for virtual destructors are actually pairs of entries. The first destructor, called the complete object destructor, performs the destruction without calling delete() on the object. The second destructor, called the deleting destructor, calls delete() after destroying the object. Both destroy any virtual bases; a separate, non-virtual function, called the base object destructor, performs destruction of the object but not its virtual base subobjects, and does not call delete().
This would also be consistent with the fact it does not happens on Windows, as it does not have deleting destructors (https://github.com/dlang/dmd/pull/8277/files#diff-1f486819d91e59db2f2dc9de45b7e612R119)
Closing this as WORKSFORME.