Bug 22636 – Wrong C++ constructor called for abstract class

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-12-29T12:51:37Z
Last change time
2024-12-13T19:20:10Z
Keywords
C++, mangling
Assigned to
No Owner
Creator
Tim
See also
https://issues.dlang.org/show_bug.cgi?id=20208
Moved to GitHub: dmd#20031 →

Comments

Comment #0 by tim.dlang — 2021-12-29T12:51:37Z
Wrong C++ constructor called for abstract class //////////////// testabstractcpp.cpp //////////////// class C { public: C(); virtual void f() = 0; int i; }; C::C() { i = 5; } ////////////////// testabstractd.d ////////////////// extern(C++) abstract class C { this(); abstract void f(); int i; } extern(C++) class D : C { override void f() { assert(i == 5); } } void main() { D d = new D(); d.f(); } ///////////////////////////////////////////////////// The files can be compiled with the following commands: clang++ -c testabstractcpp.cpp dmd -L-lstdc++ testabstractd.d testabstractcpp.o The second command results in a linker error: /usr/bin/ld: testabstractd.o:(.data._D13testabstractd1C7__ClassZ+0x88): undefined reference to `C::C()' /usr/bin/ld: testabstractd.o: in function `D::D()': testabstractd.d:(.text._ZN1DC1Ev[_ZN1DC1Ev]+0x14): undefined reference to `C::C()' The Itanium C++ ABI has different constructors. Clang seems to only emit the base object constructor (_ZN1CC2Ev) for abstract class C, but dmd tries to use the complete object constructor (_ZN1DC1Ev). The example work with GCC, because it emits both constructors.
Comment #1 by robert.schadek — 2024-12-13T19:20:10Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20031 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB