copy-ctor's

Exil Exil at gmall.com
Sun May 26 01:53:03 UTC 2019


On Saturday, 25 May 2019 at 23:15:05 UTC, Manu wrote:
> So, it seems that if an object has a postblit and a copy 
> constructor, the postblit is preferred.
>
> It also seems that if an object has a copy constructor and a 
> MEMBER with a postblit, then object has a postblit generated 
> which calls through to the member, and that is preferred.
>
> I have also noticed that if you have a union containing an item 
> with a postblit, the postblit is always called, even if the 
> item in the union is not valid:
>
> struct S(T)
> {
>   union {
>     int x = 0;
>     T y = void;
>   }
>   bool isT = false;
> }
>
> S a;
> S b = a; // calls `y's postblit, even though it's `isT` is 
> false and
> the object is `void` initialised...
>
> So, it's very hard to craft a tool like 'S', when the supplied 
> T might have a postblit and ruin everything. What are my 
> options here?
>
> Also, `hasElaborateCopyConstructor` is broken now. It should 
> know about copy ctor's.

Seems a union also calls the postblit for every object in a 
union, which makes less sense, since only one of them should be 
valid at a time.

IIRC there was also a problem with copy constructors conflicting 
with the default constructor initalizers. Would probably be best 
to iron out all these bugs now before it gets used too much.


More information about the Digitalmars-d mailing list