I'm hereby strictly referring to the c++ draft (N4659). Given the following example,
int&& f();
auto x5a = f(); // decltype(x5a) is int
I'm not sure why the deduced type is int, instead of int&&. Scott Meyers said in his book that
..., the reference-ness of an initializing expression is ignored.
However, I couldn't find any paragraph in the above draft which ensures the statement. Here's the steps I took in order to deduce the type:
According to 10.1.7.4.1 [dcl.type.auto.deduct] paragraph 2,
A type
Tcontaining a placeholder type, and a corresponding initializere, are determined as follows:- ...
- for a variable declared with a type that contains a placeholder type,
Tis the declared type of the variable andeis the initializer...
Therefore,
Tisauto, andeisf().As per 10.1.7.4.1 [dcl.type.auto.deduct] paragraph 4,
If the placeholder is the auto type-specifier, ... Obtain
PfromTby replacing the occurrences of auto with either a new invented type template parameterUor, ... Deduce a value forU"using the rules of template argument deduction from a function call", wherePis a function template parameter type and the corresponding argument ise...Therefore,
PisU, andAisint&&.According to 17.8.2.1 [temp.deduct.call] paragraph 2,
If
Pis not a reference type:- If
Ais an array type, ... - If
Ais a function type, ... - If
Ais a cv-qualified type, ...
Although
P = Uis indeed not a reference type,A = int&&stays that way because the three cases above are not applicable toA.- If
These are the only paragraphs that I've found which I think is relevant to this particular case. In conclusion, U = int&&, and the entire T is also int&&.
I'm definitely missing something here, and I'm not sure what those are. If you're kind enough to answer this question, would you confine yourself to the formal wording (with the help of the c++ draft or standard)?