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.
Comment #1 by r.sagitario — 2018-06-16T13:02:38Z
Comment #2 by turkeyman — 2018-06-18T03:01:39Z
Fix was merged.
Comment #3 by github-bugzilla — 2018-06-25T20:13:12Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/403d5f0148abe60ac1836da9038c18cebd8b8644 fix Issue 18966 - extern(C++) constructor should match C++ semantics assigning vtable set vtbl after exlicit or implicit call to super() in C++ constructors https://github.com/dlang/dmd/commit/297844f035be1753cbbf07f9338c6383b2b62708 Merge pull request #8362 from rainers/issue18966 fix Issue 18966 - extern(C++) constructor should match C++ semantics … merged-on-behalf-of: David Nadlinger <[email protected]>