<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 15 Aug 2024 at 00:31, kinke via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesday, 14 August 2024 at 13:56:08 UTC, Manu wrote:<br>
> Well, the condition is that NRVO should elide the copy/move... <br>
> it should be<br>
> constructed at the caller's scope in this case.<br>
> Your example `Thing(null).field` is not the same thing, because <br>
> it's not<br>
> NRVO at all.<br>
><br>
> I guess this is a bug then?<br>
<br>
When actually using NRVO (`auto r = Thing(null); return r;`), one <br>
even gets the error *twice*. So that's definitely a bug, the <br>
destruction is handled by the caller; just for the attributes <br>
check etc., there's no real dtor call in `fun()`.<br>
<br>
What you have is a case for RVO; AFAIK, LDC and GDC implement <br>
that (for non-POD types at least), no idea about DMD. Meaning <br>
that the temporary in the return expression isn't destructed by <br>
`foo` either; it's emplaced directly into the caller-allocated <br>
return value, as the NRVO case.<br></blockquote><div><br></div><div>My understanding is that RVO is in the D spec and NOT simply an optimisation. The language shouldn't attempt to call a destructor here in my case under any circumstances...</div><div><br></div><div>Walter? <br></div></div></div>