Skip to content

Commit 5611dea

Browse files
committed
CWG2875 Missing support for round-tripping null pointer values through indirection/address operators
1 parent 05f7548 commit 5611dea

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

source/compatibility.tex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,32 @@
30413041
(for instance, via the C typedef in \libheaderref{stdbool.h})
30423042
is ill-formed in \Cpp{}.
30433043

3044+
\diffref{expr.unary.op}
3045+
\change
3046+
In certain contexts,
3047+
taking the address of a dereferenced null or past-the-end pointer value
3048+
is well-defined in C (and yields the original pointer value),
3049+
but results in undefined behavior in \Cpp{}.
3050+
For example:
3051+
\begin{codeblock}
3052+
void f() {
3053+
char *p = nullptr;
3054+
char *p2 = &*p; // well-defined in C, undefined behavior in \Cpp{}
3055+
char *p3 = &p[0]; // well-defined in C, undefined behavior in \Cpp{}
3056+
int a[5];
3057+
int *q = &a[5]; // well-defined in C, undefined behavior in \Cpp{}
3058+
}
3059+
\end{codeblock}
3060+
\rationale
3061+
Consistent treatment of lvalues in \Cpp{}.
3062+
\effect
3063+
Well-formed and well-defined C code exhibits undefined behavior in \Cpp{}.
3064+
\difficulty
3065+
Syntactic transformation to pointer arithmetic
3066+
and possible addition of a check for null pointer values.
3067+
\howwide
3068+
Occasionally.
3069+
30443070
\diffref{expr.sizeof,expr.cast}
30453071
\change
30463072
In \Cpp{}, types can only be defined in declarations, not in expressions.\\

0 commit comments

Comments
 (0)