https://issues.dlang.org/show_bug.cgi?id=22815

          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: nob...@puremagic.com
          Reporter: ki...@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
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.

--

Reply via email to