<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2933</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="2933"></A><H4>2933.
  
Dangling references
</H4>
<B>Section: </B>7.2.2&#160; [<A href="https://wg21.link/expr.type">expr.type</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Brian Bi
 &#160;&#160;&#160;

 <B>Date: </B>2024-09-04<BR>


<P>[Accepted as a DR at the November, 2024 meeting.]</P>



<P>
<A HREF="453.html">Issue 453</A> clarified that there are no
empty lvalues, and undefined behavior ensues when trying to create
one.  However, the wording now does not specify the behavior of
dangling references, where the storage of the referenced object has
gone away.</P>

<P><B>Proposed resolution (approved by CWG 2024-11-08):</B></P>

<OL>
<LI>
<P>Change in 6.9.2 [<A href="https://wg21.link/basic.fundamental#4">basic.fundamental</A>] paragraph 4 as follows:</P>

<BLOCKQUOTE>

A pointer value P is valid in the context of an evaluation E if P
is <INS>a pointer to function or</INS> a null pointer value, or if it
is a pointer to or past the end of an object O and E happens before
the end of the duration of the region of storage for O. If a pointer
value P is used in an evaluation E and P is not valid in the context
of E, then ...

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 7.2.2 [<A href="https://wg21.link/expr.type#1">expr.type</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

If an expression initially has the type &#8220;reference to T&#8221;
(9.3.4.3 [<A href="https://wg21.link/dcl.ref">dcl.ref</A>], 9.5.4 [<A href="https://wg21.link/dcl.init.ref">dcl.init.ref</A>]), the type
is adjusted to T prior to any further analysis<INS>; the value
category of the expression is not altered</INS>.
<DEL>The expression designates</DEL>
<INS>Let <I>X</I> be</INS> the object or function denoted by the
reference<DEL>, and the expression is an lvalue or an xvalue,
depending on the expression</DEL>.  <INS>If a pointer to <I>X</I>
would be valid in the context of the evalution of the expression
(6.9.2 [<A href="https://wg21.link/basic.fundamental">basic.fundamental</A>]), the result designates <I>X</I>;
otherwise, the behavior is undefined.</INS>

</BLOCKQUOTE>
</LI>
</OL>

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