<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 988</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="988"></A><H4>988.
  
Reference-to-reference collapsing with <TT>decltype</TT>
</H4>
<B>Section: </B>9.2.9.3&#160; [<A href="https://wg21.link/dcl.type.simple">dcl.type.simple</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Michael Wong
 &#160;&#160;&#160;

 <B>Date: </B>19 October, 2009<BR>


<P>[Voted into WP at March, 2010 meeting.]</P>

<P>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 <TT>decltype</TT>:</P>

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

<P><B>Proposed resolution (October, 2009):</B></P>

<OL>
<LI><P>Delete 9.2.4 [<A href="https://wg21.link/dcl.typedef#9">dcl.typedef</A>] paragraph 9:</P></LI>

<BLOCKQUOTE>

<DEL>If a typedef <TT>TD</TT> names a type that is a reference to a
type <TT>T</TT>, an attempt to create the type &#8220;lvalue reference
to <I>cv</I> <TT>TD</TT>&#8221; creates the type &#8220;lvalue
reference to <TT>T</TT>,&#8221; while an attempt to create the type
&#8220;rvalue reference to <I>cv</I> <TT>TD</TT>&#8221; creates the type <TT>TD</TT>. [<I>Example:</I> ... &#8212;<I>end example</I>]</DEL>

</BLOCKQUOTE>

<LI><P>Delete 13.4.2 [<A href="https://wg21.link/temp.arg.type#4">temp.arg.type</A>] paragraph 4:</P></LI>

<BLOCKQUOTE>

<DEL>If a <I>template-argument</I> for a <I>template-parameter</I>
<TT>T</TT> names a type that is a reference to a type <TT>A</TT>, an
attempt to create the type &#8220;lvalue reference to <I>cv</I>
<TT>T</TT>&#8221; creates the type &#8220;lvalue reference to
<TT>A</TT>,&#8221; while an attempt to create the type &#8220;rvalue
reference to <I>cv</I> <TT>T</TT>&#8221; creates the type <TT>T</TT>
[<I>Example:</I> ... &#8212;<I>end example</I>]</DEL>

</BLOCKQUOTE>

<LI><P>Add the following as a new paragraph at the end of 9.3.4.3 [<A href="https://wg21.link/dcl.ref">dcl.ref</A>]:</P></LI>

<BLOCKQUOTE>

<P><INS>If a typedef (9.2.4 [<A href="https://wg21.link/dcl.typedef">dcl.typedef</A>]), a type
<I>template-parameter</I> (13.4.2 [<A href="https://wg21.link/temp.arg.type">temp.arg.type</A>]), or a
<I>decltype-specifier</I> (9.2.9.3 [<A href="https://wg21.link/dcl.type.simple">dcl.type.simple</A>]) denotes a
type <TT>TR</TT> that is a reference to a type <TT>T</TT>, an attempt
to create the type &#8220;lvalue reference to <I>cv</I>
<TT>TR</TT>&#8221; creates the type &#8220;lvalue reference to
<TT>T</TT>,&#8221; while an attempt to create the type &#8220;rvalue
reference to <I>cv</I> <TT>TR</TT>&#8221; creates the type <TT>TR</TT>. [<I>Example:</I></INS></P>

<PRE>
<INS>   int i;
   typedef int&amp; LRI;
   typedef int&amp;&amp; RRI;
   LRI&amp; r1 = i;                      // r1<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;
   const LRI&amp; r2 = i;                // r2<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;
   const LRI&amp;&amp; r3 = i;               // r3<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;
   RRI&amp; r4 = i;                      // r4<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;
   RRI&amp;&amp; r5 = i;                     // r5<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;&amp;

   decltype(r2)&amp; r6 = i;             // r6<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;
   decltype(r2)&amp;&amp; r7 = i;            // r7<SPAN CLASS="cmnt"> has the type </SPAN>int&amp;</INS>
</PRE>

<P><INS>&#8212;<I>end example</I>]</INS></P>

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
