With regard to holding the placeholder type

I hereby refer strictly to the C ++ project ( N4659 ). In the following example

int&& f();
auto x5a = f(); // decltype(x5a) is int

      

I'm not sure why the inferred type int

insteadint&&

. Scott Meyers said in his book that

..., the reference to the initialization expression is ignored.

However, I have not been able to find any paragraph in the above project that provides an assertion. Here are the steps taken to infer the type:

  • According to clause 10.1.7.4.1 [dcl.type.auto.deduct] clause 2,

    A type T

    containing a placeholder type and a corresponding initializer e

    is defined 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 an initializer ...

    Therefore, T

    - auto

    , a e

    - f()

    .

  • According to clause 10.1.7.4.1 [dcl.type.auto.deduct],

    If the placeholder is an automatic type specifier, ... Get P

    from T

    , replacing the occurrences auto with either the newly invented template type, U

    or, ... Derive the value for U

    "using the rules of template argument deduction from a function call , where P

    is the type of the function template parameter, and the corresponding argument e

    ...

    Therefore, P

    - U

    , a A

    - int&&

    .

  • According to clause 17.8.2.1 [temp.deduct.call],

    If P

    not a reference type:

    • If A

      is an array type, ...
    • If A

      is a function type, ...
    • If A

      is a cv-qualified type, ...

    Although P = U

    not really a reference type, it A = int&&

    remains so because the above three cases do not apply to A

    .

These are the only paragraphs I have found that I think are relevant to this particular case. In conclusion, U = int&&

and all T

as well int&&

.

I'm definitely missing something here and I'm not sure what it is. If you are kind enough to answer this question, would you limit yourself to formal wording (with a C ++ draft or standard)?

+3


source to share





All Articles