Bug 22815 – extern(C++) constructor cannot be used from C++ (no init symbol blit)

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-22T22:31:52Z
Last change time
2024-12-13T19:21:09Z
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#20060 →

Comments

Comment #0 by kinke — 2022-02-22T22:31:52Z
In D, compiler/druntime pre-initialize each class instance (extern(D) and extern(C++) etc.) by blitting the init symbol (incl. vptr) before invoking a constructor. In C++, the constructor initializes the fields directly. So if we call a C++ one from a matching extern(C++) declaration in D, we do a little bit of extra work with the pre-init blit. The real issue is that invoking an extern(C++) definition from C++ might likely result in incomplete initialization / undefined behavior. Note that simply inserting the full blit as first statement in each extern(C++) ctor isn't desirable in case of class hierarchies with super(…) calls, or other this(…) calls. Related in this regard: https://issues.dlang.org/show_bug.cgi?id=18966 Maybe we should start with deprecating extern(C++) ctor *definitions* for now. Declaring one defined in C++ is fine.
Comment #1 by robert.schadek — 2024-12-13T19:21:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20060 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB