From a488f1d8b529b6d0dff0c76b43a77700cd81583d Mon Sep 17 00:00:00 2001 From: hsutter Date: Mon, 18 Jun 2018 11:44:29 -0700 Subject: [PATCH] Added F.48, closes #1219 --- CppCoreGuidelines.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 442379e..f58e752 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2310,6 +2310,7 @@ Parameter passing semantic rules: * [F.45: Don't return a `T&&`](#Rf-return-ref-ref) * [F.46: `int` is the return type for `main()`](#Rf-main) * [F.47: Return `T&` from assignment operators](#Rf-assignment-op) +* [F.48: Don't `return std::move(local)`](#Rf-return-move-local) Other function rules: @@ -3686,6 +3687,34 @@ This was primarily to avoid code of the form `(a = b) = c` -- such code is not c This should be enforced by tooling by checking the return type (and return value) of any assignment operator. + +### F.48: Don't `return std::move(local)` + +##### Reason + +With guaranteed copy elision, it is now almost always a pessimization to expressly use `std::move` in a return statement. + +##### Example; bad + + S f() + { + S result; + return std::move(result); + } + +##### Example; good + + S f() + { + S result; + return result; + } + +##### Enforcement + +This should be enforced by tooling by checking the return expression . + + ### F.50: Use a lambda when a function won't do (to capture local variables, or to write a local function) ##### Reason