[Issue 8931] array/slice assignment causes destruction + postblit instead of opAssign

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 24 01:08:14 PDT 2015


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

--- Comment #6 from monarchdodra at gmail.com ---
(In reply to Jonathan M Davis from comment #5)
> (In reply to monarchdodra from comment #4)
> > I did some extra thinking about this, and this might be invalid. While one
> > might "expect" opAssign to be called, doing this would mean it is impossible
> > to have a strong exception safe behavior should one of the assignements
> > fails.
> 
> IIRC, isn't opAssign actually supposed to assign to a copy and then have the
> result blitted into the variable that you're actually assigning to in order
> to make it exception safe like you're concerned about? The extension of that
> would be to do opAssign into a copy of the static array, and then blit it
> into the original afterwards. I'm not sure how desirable that is, but it
> would be an extension of what happens with opAssign in general (assuming
> that I'm remembering that right).

Well (IIRC), not exactly. The *default* implementation of opAssign, provided
you implemented "this(this)" works that way, yes. However, once you *do* define
opAssign, the all bets are off. The compiler calls your opAssign, and you have
to make your own guarantees.

That said, back to my original comment, the current implementation postblits
the elements 1 at a time anyways, so the exception safety is just as bad as
assigning the elements 1 at a tie.

--


More information about the Digitalmars-d-bugs mailing list