test.cpp
--------
struct Test
{
Test() : ptr(nullptr) {}
Test(const Test& x)
{
ptr = x.ptr + 10;
}
char* ptr;
};
int test(Test p);
int main()
{
Test x;
test(x);
return 0;
}
test.d
------
extern(C++):
struct Test
{
this(this)
{
ptr += 10;
}
char* ptr;
}
int test(Test p)
{
assert(p.ptr == null);
return 10;
}
--------------------------------------------
When I build and run this, passing `x` to test() by value crashes. The function receives garbage.
If you remove the copy constructors (pass this same struct as a POD), it works fine!
This was tested in Linux 64bit, against GCC-7.
If it makes any difference, I supplied `-std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0` to the C compiler.
Comment #1 by sprink.noreply — 2019-02-08T01:54:57Z
@look-at-me created dlang/dmd pull request #9434 "Fix Issue 19563 Fix extern(C++) Incorrect ABI passing small struct" mentioning this issue:
- Fix Issue 19563 Fix extern(C++) Incorrect ABI passing small struct
https://github.com/dlang/dmd/pull/9434
Comment #5 by dlang-bot — 2019-03-12T02:46:26Z
dlang/dmd pull request #9434 "Fix Issue 19563 Fix extern(C++) Incorrect ABI passing small struct" was merged into master:
- bb2892490ee0df3f3fda486e8e549fdb4e58e37b by look-at-me:
Fix Issue 19563 Fix extern(C++) Incorrect ABI passing small struct
https://github.com/dlang/dmd/pull/9434