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>
This commit is contained in:
Jan Schultke
2024-04-11 18:59:42 +02:00
committed by GitHub
parent 2a2581cc95
commit c91ea43aba

View File

@@ -3932,11 +3932,13 @@ value) of any assignment operator.
##### Reason ##### 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 ##### Example, bad
S f() S bad()
{ {
S result; S result;
return std::move(result); return std::move(result);
@@ -3944,9 +3946,10 @@ With guaranteed copy elision, it is now almost always a pessimization to express
##### Example, good ##### Example, good
S f() S good()
{ {
S result; S result;
// Named RVO: move elision at best, move construction at worst
return result; return result;
} }