[Issue 16060] New: extern(C++) abstract base class and interface
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun May 22 18:16:43 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16060
Issue ID: 16060
Summary: extern(C++) abstract base class and interface
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: turkeyman at gmail.com
In this case, we have an example of single-inheritance in C++, but D treats
this construct as multiple-inheritance, and the struct's don't match.
C++:
----
#include <new>
class I
{
public:
virtual void f1() = 0;
virtual float f2() = 0;
};
class Test : public I
{
public:
int t;
Test(int t) : t(t) {}
};
class Blah : public Test
{
public:
Blah() : Test(0xbaadf00d) {}
void f1() {}
float f2() { return 10.f; }
};
extern "C" {
I* test()
{
return new Blah;
}
Test* test2()
{
return new Blah;
}
}
D:
--
import std.stdio;
extern (C++) interface I
{
void f1();
float f2();
}
extern (C++) abstract class Test : I
{
int t;
}
extern (C) I test();
extern (C) Test test2();
int main(string[] argv)
{
auto i = test();
i.f1();
auto j = test2();
float f = j.f2(); // CRASH! looks up vtable address: [i + 8], expect: vtable
at [i]
writeln("Hello D-World! ", f);
return 0;
}
--
More information about the Digitalmars-d-bugs
mailing list