Title
Dangling references
Status
open
Section
7.2.2 [expr.type]
Submitter
Brian Bi

Created on 2024-09-04.00:00:00 last changed 1 month ago

Messages

Date: 2024-09-09.14:38:27

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.

Possible resolution:

  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.
History
Date User Action Args
2024-09-04 00:00:00admincreate