Added F.48, closes #1219

This commit is contained in:
hsutter
2018-06-18 11:44:29 -07:00
parent c0a2efdfe8
commit a488f1d8b5

View File

@@ -2310,6 +2310,7 @@ Parameter passing semantic rules:
* [F.45: Don't return a `T&&`](#Rf-return-ref-ref) * [F.45: Don't return a `T&&`](#Rf-return-ref-ref)
* [F.46: `int` is the return type for `main()`](#Rf-main) * [F.46: `int` is the return type for `main()`](#Rf-main)
* [F.47: Return `T&` from assignment operators](#Rf-assignment-op) * [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: 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 This should be enforced by tooling by checking the return type (and return
value) of any assignment operator. value) of any assignment operator.
### <a name="Rf-return-move-local"></a>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 .
### <a name="Rf-capture-vs-overload"></a>F.50: Use a lambda when a function won't do (to capture local variables, or to write a local function) ### <a name="Rf-capture-vs-overload"></a>F.50: Use a lambda when a function won't do (to capture local variables, or to write a local function)
##### Reason ##### Reason