June 10, 2018 [Issue 18966] New: extern(C++) constructor should match C++ semantics assigning vtable | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: turkeyman@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. -- |
Copyright © 1999-2021 by the D Language Foundation