D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18986 - OSX/FreeBSD: allocating an instance of a C++ class fails
Summary: OSX/FreeBSD: allocating an instance of a C++ class fails
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-14 06:30 UTC by Rainer Schuetze
Modified: 2024-12-13 18:59 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2018-06-14 06:30:13 UTC
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.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:59:09 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17864

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB