[Issue 18986] New: OSX/FreeBSD: allocating an instance of a C++ class fails
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 14 06:30:13 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18986
Issue ID: 18986
Summary: OSX/FreeBSD: allocating an instance of a C++ class
fails
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: r.sagitario at gmx.de
When allocating a C++ class instance with the constructor defined in C++, the
wrong object address is used:
// testcpp.cpp
class Cpp
{
public:
Cpp();
virtual void foo() {}
int x;
};
Cpp::Cpp()
{
x = 42;
}
// testd.d
extern(C++)
{
class Cpp
{
public:
this();
void foo();
int x;
}
}
void main()
{
Cpp c = new Cpp;
assert(c.x == 42);
}
The assertion fails for OSX and FreeBSD, but not on Windows and Linux. This
happens because the constructor does not return 'this' on the former platforms.
--
More information about the Digitalmars-d-bugs
mailing list