[Issue 17448] Move semantics cause memory corruption and cryptic bugs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 30 17:09:33 UTC 2022


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

--- Comment #51 from Steven Schveighoffer <schveiguy at gmail.com> ---
(In reply to Tomer Filiba (weka) from comment #48)
> Steven, can we agree that the following snippet is NOT okay? 
> Regardless of @safe, let's leave it out of question.

You are still not hooking copies or destructors. In this case, if I add a
postblit to your struct like:

```d
this(this) { lastS = &this; }
```

then it works as expected. In this case, the compiler is copying the S(x)
instance to the return value, and then destroying the original, though I'm
somewhat surprised NRVO didn't kick in here.

In any case, I have found an answer to my question that the compiler *does*
perform moves in certain situations, and it does not call opPostMove.

--


More information about the Digitalmars-d-bugs mailing list