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

2024-12-16


2933. Dangling references

Section: 7.2.2  [expr.type]     Status: DR     Submitter: Brian Bi     Date: 2024-09-04

[Accepted as a DR at the November, 2024 meeting.]

Issue 453 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.

Proposed resolution (approved by CWG 2024-11-08):

  1. Change in 6.8.2 [basic.fundamental] paragraph 4 as follows:

    A pointer value P is valid in the context of an evaluation E if P is a pointer to function or 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 ...
  2. Change in 7.2.2 [expr.type] paragraph 1 as follows:

    If an expression initially has the type “reference to T” (9.3.4.3 [dcl.ref], 9.4.4 [dcl.init.ref]), the type is adjusted to T prior to any further analysis; the value category of the expression is not altered. The expression designates Let X be the object or function denoted by the reference, and the expression is an lvalue or an xvalue, depending on the expression. If a pointer to X would be valid in the context of the evalution of the expression (6.8.2 [basic.fundamental]), the result designates X; otherwise, the behavior is undefined.