[Issue 17448] Move semantics cause memory corruption and cryptic bugs
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue May 30 20:35:49 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17448
--- Comment #12 from Walter Bright <bugzilla at digitalmars.com> ---
Interestingly, if you change:
auto f() {
return CallContext(18);
}
to:
auto f() {
CallContext c = CallContext(18);
return c;
}
it will work, i.e. no moving is done. This is because the compiler does NRVO
(Named Return Value Optimization) on it, where the object is constructed
directly into its final destination.
It's obviously not doing this for the original return statement, likely because
it does not have a name :-)
I'll look into correcting this, as NRVO is an important optimization. But at
least you have a workaround for the moment.
--
More information about the Digitalmars-d-bugs
mailing list