Bug 16060 – extern(C++) abstract base class and interface
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2016-05-23T01:16:43Z
Last change time
2021-03-24T13:03:13Z
Keywords
industry
Assigned to
No Owner
Creator
Manu
Comments
Comment #0 by turkeyman — 2016-05-23T01:16:43Z
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;
}
Comment #1 by iamthewilsonator — 2021-03-24T06:31:08Z