[Issue 18966] New: extern(C++) constructor should match C++ semantics assigning vtable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 10 07:55:17 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18966
Issue ID: 18966
Summary: extern(C++) constructor should match C++ semantics
assigning vtable
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: turkeyman at gmail.com
test.cpp
------------------------------------------------
class Base
{
public:
Base() { x = 10; }
virtual ~Base() {}
virtual void vf()
{
x = 100;
}
int x;
};
Base base;
------------------------------------------------
test.d
------------------------------------------------
extern(C++):
class Base
{
this();
~this();
void vf();
int x;
}
class Derived : Base
{
this()
{
super();
}
override void vf()
{
x = 200;
}
}
void test()
{
Derived d = new Derived;
d.vf();
assert(d.x == 200);
}
------------------------------------------------
When deriving a D class from a C++ class, the vtable assignment semantics are
incompatible.
D assigns the vtable once prior to construction.
C++ assigns the vtable at the start of the ctor, immediately following the call
to super.ctor().
extern(C++) class will need to loosely follow the C++ semantic, that is:
Inside any extern(C++) constructor, any call to a super constructor must
immediately be followed by assignment of the classes vtable.
--
More information about the Digitalmars-d-bugs
mailing list