Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX/FreeBSD: allocating an instance of a C++ class fails #17864

Open
dlangBugzillaToGithub opened this issue Jun 14, 2018 · 0 comments
Open

OSX/FreeBSD: allocating an instance of a C++ class fails #17864

dlangBugzillaToGithub opened this issue Jun 14, 2018 · 0 comments
Labels
Arch:x86 Issues specific to x86 Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code P3 Severity:normal

Comments

@dlangBugzillaToGithub
Copy link

Rainer Schuetze (@rainers) reported this on 2018-06-14T06:30:13Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18986

Description

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.
@thewilsonator thewilsonator added the Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86 Issues specific to x86 Feature:extern (C/C++/Obj-C) interfacing to C, C++, Objective-C code P3 Severity:normal
Projects
None yet
Development

No branches or pull requests

2 participants