Title
Reference-to-reference collapsing with decltype
Status
cd2
Section
9.2.9.3 [dcl.type.simple]
Submitter
Michael Wong

Created on 2009-10-19.00:00:00 last changed 179 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting.]

Date: 2009-10-15.00:00:00

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]

Date: 2009-10-19.00:00:00

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
History
Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2687
2010-03-29 00:00:00adminsetstatus: ready -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2349
2009-10-19 00:00:00admincreate