Generated opAssign in the presence of a copy constructor

Manu turkeyman at gmail.com
Thu Jul 26 16:10:39 UTC 2018


On Thu., 26 Jul. 2018, 2:45 am RazvanN via Digitalmars-d, <
digitalmars-d at puremagic.com> wrote:

>
> void opAssign(ref $q1 S rhs)    // version 3
> {
>      S tmp1 = rhs;                // call copy constructor
>      void[S.sizeof] tmp2 = void;
>
>      // swapbits(tmp1, this);
>      memcpy(tmp2, this);
>      memcpy(this, tmp1);
>      memcpy(tmp1, tmp2);
>
>      tmp1.__dtor();
> }
>

Uh oh, you feel for the trap!
You can't destruct like this.
__xdtor at least, but even then it's not so simple.

I think emplace() should be lifted to druntime, and destroy() should be
complemented by destruct(), which will not post-assign .init.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20180726/f1b3b608/attachment.html>


More information about the Digitalmars-d mailing list