Open
Description
These usages of pointer indirection are explicitly allowed in C via WG14 N721, but seemly not allowed in C++.
int* p = &(*((int*)0)); // undefined behavior in C++, well-defined in C (DR076/N721)
int a[10];
int* q = &a[10]; // undefined behavior in C++, well-defined in C (DR076/N721)
Should we mention them in [diff.expr]?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
xmh0511 commentedon Jun 6, 2022
This is CWG232. A good question located at https://stackoverflow.com/questions/47227977/is-dereferencing-invalid-pointers-legal-if-no-lvalue-to-rvalue-conversion-occurs/47229011#47229011
[-][diff.expr] Unmentioned incompatibility with C about pointer indirection[/-][+][diff.expr] Unmentioned incompatibility with C about pointer indirection CWG232[/+]frederick-vs-ja commentedon Jun 6, 2022
Thank you!
I find that this change is essentially a DR in C (DR076). And the proposed resolution of CWG232 is significantly more permissive than that of C.
frederick-vs-ja commentedon Nov 10, 2023
Reopening as CWG232 is closed as NAD.
Perhaps such incompatibility is intended.
[-][diff.expr] Unmentioned incompatibility with C about pointer indirection CWG232[/-][+][diff.expr] Unmentioned incompatibility with C about pointer indirection CWG2875[/+]frederick-vs-ja commentedon Mar 20, 2024
Addressed by CWG2875.