[Issue 18894] extern(C++) interfaces + OSX

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 21 04:03:14 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=18894

Mathias LANG <pro.mathias.lang at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |pro.mathias.lang at gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #1 from Mathias LANG <pro.mathias.lang at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list