www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22815] New: extern(C++) constructor cannot be used from C++


          Issue ID: 22815
           Summary: extern(C++) constructor cannot be used from C++ (no
                    init symbol blit)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

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

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
this(…) calls. Related in this regard:

Maybe we should start with deprecating extern(C++) ctor *definitions* for now.
Declaring one defined in C++ is fine.

Feb 22 2022