Bug 18966 – extern(C++) constructor should match C++ semantics assigning vtable
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-10T07:55:17Z
Last change time
2018-06-25T20:13:12Z
Keywords
C++, industry, pull
Assigned to
No Owner
Creator
Manu
Comments
Comment #0 by turkeyman — 2018-06-10T07:55:17Z
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.