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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 24 10:53:25 PDT 2015


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

--- Comment #7 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to monarchdodra from comment #6)
> (In reply to Jonathan M Davis from comment #5)
> > 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.

Hmmm. Well, I don't know how to test that to figure out what's going on, given
that bitblitting is involved and thus you have no functions to add code to
print out or whatnot. I guess that the only way to figure out what's happening
for sure would be to read the assembly, and I'm not very good at that.

> 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.

Which is why I was suggesting that one solution might be to do it all into
another static array first and then blit that over after it succeeds. I'm not
sure that that's a _good_ solution, since it requires blitting everything over,
but it would at least theoretically give you the exception safety.

Either way, it seems rather odd to be using postblits instead of opAssign when
doing assignment, even if it's in a static array.

--


More information about the Digitalmars-d-bugs mailing list