Pre C ++ 1y the copied version of the return is identical if we look at the C ++ 11 draft 6.6 Transition operators, the grammar for the return:
return expression opt ;
return braced-init-list;
an expression can be any expression, and we can see from section 5.1 . Key expressions say (emphasis mine forward):
The expression in parentheses is the primary expression, the type and value are identical to the values of the attached expression. The presence of parentheses does not affect whether the expression is a value of l. An expression in parentheses can be used in exactly the same contexts as those in which a closed expression can be used, and with the same unless otherwise indicated .
In C ++ 1y, we can use delctype (auto) to infer return types, and this changes the situation, as we can see from the C ++ 1y draft standard section 7.1.6.4 auto specifier says:
When a variable declared using a placeholder type is initialized, or return occurs in a function declared with a return type that contains a placeholder type, the output type of the return value or the type of the variable is determined by the type of its initializer . [...]
and contains the following examples:
auto x3a = i; // decltype (x3a) - int
decltype (auto) x3d = i; // decltype (x3d) - int
auto x4a = (i); // decltype (x4a) - int
decltype (auto) x4d = (i); // decltype (x4d) - int &
and we can see that there is a difference when using delctype (auto) expressions and in parentheses. The rule that applies consists of clause 7.1.6.2 specifications of a simple type, which states:
For the expression e, the type designated as decltype (e) is defined as follows:
and includes the following bullets:
- if e is an unsferonized id-expression or an unbiased membership access class (5.2.5), decltype (e) is the type of object called e. If such an object is absent or if e calls a set of overloaded functions, the program is poorly formed;
and
- otherwise, if e is an lvalue, decltype (e) is T &, where T is the type of e;