diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 6de8e6e..038830a 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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; }