Who says we can't call C++ constructors?
kinke
kinke at libero.it
Tue Apr 24 14:24:04 UTC 2018
On Tuesday, 24 April 2018 at 11:19:59 UTC, Atila Neves wrote:
> Odd then that dmd doesn't try to correctly mangle constructors
> and destructors since they're perfectly callable.
For normal constructors, that only works in the
C++-ctor-called-from-D direction, with suboptimal performance.
Reason being that the D compiler blits the T.init value over the
instance before calling a ctor, and the D ctor not having to
define all members.
So for a C++ ctor called from D, the pre-construction blit is
useless extra work, and calling a D ctor from C++ is unsafe as
the D ctor may not set all fields. The latter could be simply
implemented by C++ ctor wrappers for all D ctors (for extern(C++)
structs and classes), performing the T.init blit and then calling
the corresponding D ctor, see
https://forum.dlang.org/post/nqxsdehlydizatoprrax@forum.dlang.org.
For the dtor, IIRC the problem was that it's usually virtual in
C++ (at least when planning to allow subtyping) but isn't in D.
More information about the Digitalmars-d-announce
mailing list