This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


988. Reference-to-reference collapsing with decltype

Section: 9.2.9.3  [dcl.type.simple]     Status: CD2     Submitter: Michael Wong     Date: 19 October, 2009

[Voted into WP at March, 2010 meeting.]

References to references are ill-formed, but special provision is made in cases where this occurs via typedefs or template type parameters. A similar provision is probably needed for types resulting from decltype:

    int x, *p = &x;
    decltype(*p) &y = *p;  // reference to reference is ill-formed

Proposed resolution (October, 2009):

  1. Delete 9.2.4 [dcl.typedef] paragraph 9:

  2. If a typedef TD names a type that is a reference to a type T, an attempt to create the type “lvalue reference to cv TD” creates the type “lvalue reference to T,” while an attempt to create the type “rvalue reference to cv TD” creates the type TD. [Example: ... —end example]
  3. Delete 13.4.2 [temp.arg.type] paragraph 4:

  4. If a template-argument for a template-parameter T names a type that is a reference to a type A, an attempt to create the type “lvalue reference to cv T” creates the type “lvalue reference to A,” while an attempt to create the type “rvalue reference to cv T” creates the type T [Example: ... —end example]
  5. Add the following as a new paragraph at the end of 9.3.4.3 [dcl.ref]:

  6. If a typedef (9.2.4 [dcl.typedef]), a type template-parameter (13.4.2 [temp.arg.type]), or a decltype-specifier (9.2.9.3 [dcl.type.simple]) denotes a type TR that is a reference to a type T, an attempt to create the type “lvalue reference to cv TR” creates the type “lvalue reference to T,” while an attempt to create the type “rvalue reference to cv TR” creates the type TR. [Example:

       int i;
       typedef int& LRI;
       typedef int&& RRI;
       LRI& r1 = i;                      // r1 has the type int&
       const LRI& r2 = i;                // r2 has the type int&
       const LRI&& r3 = i;               // r3 has the type int&
       RRI& r4 = i;                      // r4 has the type int&
       RRI&& r5 = i;                     // r5 has the type int&&
    
       decltype(r2)& r6 = i;             // r6 has the type int&
       decltype(r2)&& r7 = i;            // r7 has the type int&
    

    end example]