Concerning placeholder type deduction

Viewed 96

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:

  1. According to 10.1.7.4.1 [dcl.type.auto.deduct] paragraph 2,

    A type T containing a placeholder type, and a corresponding initializer e, are determined as follows:

    • ...
    • for a variable declared with a type that contains a placeholder type, T is the declared type of the variable and e is the initializer...

    Therefore, T is auto, and e is f().

  2. As per 10.1.7.4.1 [dcl.type.auto.deduct] paragraph 4,

    If the placeholder is the auto type-specifier, ... Obtain P from T by replacing the occurrences of auto with either a new invented type template parameter U or, ... Deduce a value for U "using the rules of template argument deduction from a function call", where P is a function template parameter type and the corresponding argument is e...

    Therefore, P is U, and A is int&&.

  3. According to 17.8.2.1 [temp.deduct.call] paragraph 2,

    If P is not a reference type:

    1. If A is an array type, ...
    2. If A is a function type, ...
    3. If A is a cv-qualified type, ...

    Although P = U is indeed not a reference type, A = int&& stays that way because the three cases above are not applicable to A.

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)?

0 Answers
Related