<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2352</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="2352"></A><H4>2352.
  
Similar types and reference binding
</H4>
<B>Section: </B>9.5.4&#160; [<A href="https://wg21.link/dcl.init.ref">dcl.init.ref</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2017-07-14<BR>


<P>[Accepted as a DR at the February, 2019 meeting.]</P>

<P>In an example like</P>

<PRE>
  int *ptr;
  const int *const &amp;f() {
    return ptr;
  }
</PRE>

<P>What is returned is a reference to a temporary instead of binding
directly to <TT>ptr</TT>. The rules for reference-related types should
say that <TT>T</TT> is reference-related to <TT>U</TT> if <TT>U*</TT>
can be converted to <TT>T*</TT> by a qualification conversion.</P>

<P><B>Notes from the April, 2018 teleconference:</B></P>

<P>CWG agreed with the proposed direction.</P>

<P><B>Proposed resolution (November, 2018):</B></P>

<P>Change 9.5.4 [<A href="https://wg21.link/dcl.init.ref#4">dcl.init.ref</A>] paragraph 4 as follows:</P>

<BLOCKQUOTE>

<P>Given types &#8220;<I>cv1</I>
<TT>T1</TT>&#8221; and &#8220;<I>cv2</I>
<TT>T2</TT>&#8221;,
&#8220;<I>cv1</I>
<TT>T1</TT>&#8221; is <I>reference-related</I>
to &#8220;<I>cv2</I>
<TT>T2</TT>&#8221; if <TT>T1</TT>
is <DEL>the same type as</DEL>
<INS>similar (7.3.6 [<A href="https://wg21.link/conv.qual">conv.qual</A>]) to</INS>
<TT>T2</TT>, or <TT>T1</TT>
is a base class
of <TT>T2</TT>. &#8220;<I>cv1</I>
<TT>T1</TT>&#8221; is <I>reference-compatible</I>
with
&#8220;<I>cv2</I>
<TT>T2</TT>&#8221; if</P>

<UL>
<LI><P>
<DEL><TT>T1</TT> is reference-related to <TT>T2</TT>, or</DEL>
</P></LI>

<LI><P>
<DEL><TT>T2</TT>
is &#8220;<TT>noexcept</TT>
function&#8221; and <TT>T1</TT>
is
&#8220;function&#8221;, where the function types are
otherwise the same,</DEL>
</P></LI>

</UL>

<P>
<DEL>and <I>cv1</I> is the same cv-qualification as, or
greater cv-qualification than, <I>cv2</I></DEL>
<INS>a prvalue of type &#8220;pointer to <I>cv2</I>
<TT>T2</TT>&#8221; can be converted to the type
&#8220;pointer to <I>cv1</I> <TT>T1</TT>&#8221; via a
standard conversion sequence
(7.3 [<A href="https://wg21.link/conv">conv</A>])</INS>. In all cases where the
<DEL>reference-related or</DEL>
reference-compatible relationship of
two types is used to establish the validity of a reference
binding<DEL>, and <TT>T1</TT> is a base class of <TT>T2</TT></DEL>
<INS>and the standard conversion sequence would be
ill-formed</INS>, a program that necessitates such a binding
is ill-formed <DEL>if <TT>T1</TT> is an inaccessible
(11.8 [<A href="https://wg21.link/class.access">class.access</A>]) or ambiguous
(6.5.2 [<A href="https://wg21.link/class.member.lookup">class.member.lookup</A>]) base class of <TT>T2</TT></DEL>.</P>

</BLOCKQUOTE>

<P><B>Additional notes (September, 2023)</B></P>

<P>
<A HREF="2018.html">Issue 2018</A> is a duplicate of this issue.</P>

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