On 6/5/22 14:57, Ali Çehreli wrote:
> struct Foo {
> Foo dup() {
> auto result = Foo(this.payload);
> // ...
> return result;
> }
> }
>
> In that case, the "named return value optimization" (NRVO) would be
> applied and the object would still be moved to 'x'.
I am wrong there as well: Technically, NRVO (or RVO) does not move but
constructs the object in the caller's stack frame.
So, if the caller has the following code:
auto z = existing.dup();
Then 'result' inside dup() is the same as caller's 'z'. Not 'result' but
'z' would be constructed in dup(). No move is performed and no value is
actually returned.
Ali