From 3d1e76e59a85d29bb3184f495cc460c92433abf9 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 28 Jul 2025 09:43:44 +0200 Subject: [PATCH 1/2] [expr.unary.op] Add a note about dereferencing a dangling pointer Dereferencing a dangling pointer to an object is valid; the resulting lvalue can be used in limited ways as per [basic.life] p8. Add a non-normative note linking the two sections together. The original wording ("If the operand points to an object...") misled me; I assumed the object would have been within its lifetime, and therefore dereferencing a dangling pointer would be UB, but the kind folks at CWG explained the correct interpretation to me -- a pointer can "point to an object" even outside that object's lifetime. --- source/expressions.tex | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/expressions.tex b/source/expressions.tex index 51ff9a3ce5..3f42519e50 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -5238,6 +5238,11 @@ the result denotes that object or function; otherwise, the behavior is undefined except as specified in \ref{expr.typeid}. \begin{note} +Indirection through a pointer to an object outside that object's +lifetime is valid. The lvalue thus obtained can be used in limited +ways, see~\ref{basic.life}. +\end{note} +\begin{note} \indextext{type!incomplete}% Indirection through a pointer to an incomplete type (other than \cv{} \keyword{void}) is valid. The lvalue thus obtained can be From dfd07dc803ed57151639d4dd1888653e1a761314 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 28 Jul 2025 12:32:18 +0200 Subject: [PATCH 2/2] Update source/expressions.tex Co-authored-by: Jens Maurer --- source/expressions.tex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/expressions.tex b/source/expressions.tex index 3f42519e50..edd0ad8654 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -5238,9 +5238,7 @@ the result denotes that object or function; otherwise, the behavior is undefined except as specified in \ref{expr.typeid}. \begin{note} -Indirection through a pointer to an object outside that object's -lifetime is valid. The lvalue thus obtained can be used in limited -ways, see~\ref{basic.life}. +Indirection through a pointer to an out-of-lifetime object is valid\iref{basic.life}. \end{note} \begin{note} \indextext{type!incomplete}%