Skip to content

[expr.unary.op] Add a note about dereferencing a dangling pointer#8130

Merged
tkoeppe merged 2 commits into
cplusplus:mainfrom
dangelog:clarify-expr-unary-op-dangling-ptr
Jul 28, 2025
Merged

[expr.unary.op] Add a note about dereferencing a dangling pointer#8130
tkoeppe merged 2 commits into
cplusplus:mainfrom
dangelog:clarify-expr-unary-op-dangling-ptr

Conversation

@dangelog
Copy link
Copy Markdown
Contributor

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.

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.
Comment thread source/expressions.tex Outdated
Co-authored-by: Jens Maurer <Jens.Maurer@gmx.net>
@tkoeppe tkoeppe merged commit 791ff12 into cplusplus:main Jul 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants