Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2025

Conversation

dangelog
Copy link
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.
@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