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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 30 17:14:37 UTC 2022


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

--- Comment #52 from Steven Schveighoffer <schveiguy at gmail.com> ---
(In reply to Steven Schveighoffer from comment #51)

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

Indeed, it's enough to disable postblit, and then NRVO kicks in. So the
compiler prefers to move vs. using NRVO when nobody cares about the
movement/copy.

And then it becomes apparent that the compiler must obey `@disable opPostMove`
if it is going to make decisions like this!

--


More information about the Digitalmars-d-bugs mailing list