Improve reasoning and examples for F.48 (#2100)

* fix incorrect reason for F.48

* distinguish rvo and nrvo

* the issue is about local, so limiting example to local

---------

Co-authored-by: Sergey Zubkov <cubbi@cubbi.com>
pull/2194/head
Jan Schultke 2 years ago committed by GitHub
parent 2a2581cc95
commit c91ea43aba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3932,11 +3932,13 @@ value) of any assignment operator.
##### Reason
With guaranteed copy elision, it is now almost always a pessimization to expressly use `std::move` in a return statement.
Returning a local variable implicitly moves it anyway.
An explicit `std::move` is always a pessimization, because it prevents Return Value Optimization (RVO),
which can eliminate the move completely.
##### Example, bad
S f()
S bad()
{
S result;
return std::move(result);
@ -3944,9 +3946,10 @@ With guaranteed copy elision, it is now almost always a pessimization to express
##### Example, good
S f()
S good()
{
S result;
// Named RVO: move elision at best, move construction at worst
return result;
}

Loading…
Cancel
Save