// OS: Linux, macOS extern(C++, "foo"): struct S { void* s; ~this() {} // or this(this) {} } interface I { S x(); } final class C : I { long l = 3; S x() { assert(l == 3); //fails return S.init; } } extern(D) void main() { auto s = new C().I.x; }
works well with LDC
Curiously, this works on Windows.
The problem here is the "adjustor thunk" generated does not take into account the size of the hidden pointer parameter, and winds up adjusting the hidden pointer rather than the `this` pointer.
@WalterBright created dlang/dmd pull request #11703 "fix Issue 20716 - Wrong code/ABI for extern(C++) interface method tha…" fixing this issue: - fix Issue 20716 - Wrong code/ABI for extern(C++) interface method that returns non-POD https://github.com/dlang/dmd/pull/11703
dlang/dmd pull request #11703 "fix Issue 20716 - Wrong code/ABI for extern(C++) interface method tha…" was merged into master: - 9ad79f65edba40925c4f4d92c5603fb5711cd85a by Walter Bright: fix Issue 20716 - Wrong code/ABI for extern(C++) interface method that returns non-POD https://github.com/dlang/dmd/pull/11703