Created on 2024-03-21.00:00:00 last changed 3 months ago
CWG 2024-06-26
Implementations are required to diagnose undefined behavior in constant expressions. The issue is kept in review status to allow time for submitting a paper to EWG to make the &a[5] case well-defined. See also C23 6.5.3.2p3.
Proposed resolution (approved by CWG 2024-06-26):
Add a new paragraph to C.7.4 [diff.expr] as follows:
Affected subclause: 7.6.2.2 [expr.unary.op]
Change: In certain contexts, taking the address of a dereferenced null or past-the-end pointer value is well-defined in C (and yields the original pointer value), but results in undefined behavior in C++. For example:void f() { char *p = 0; char *p2 = &*p; // well-defined in C, undefined behavior in C++ char *p3 = &p[0]; // well-defined in C, undefined behavior in C++ int a[5]; int *q = &a[5]; // well-defined in C, undefined behavior in C++ }Rationale: Consistent treatment of lvalues in C++.
Effect on original feature: Well-formed and well-defined C code exhibits undefined behavior in C++.
Difficulty of converting: Syntactic transformation to pointer arithmetic and possible addition of a check for null pointer values.
How widely used: Occasionally.
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-06-26 19:00:47 | admin | set | messages: + msg7757 |
2024-06-26 19:00:47 | admin | set | status: tentatively ready -> review |
2024-05-17 22:24:28 | admin | set | messages: + msg7701 |
2024-05-17 22:24:28 | admin | set | status: open -> tentatively ready |
2024-03-21 00:00:00 | admin | create |