Skip to content

Commit 4c2bc49

Browse files
burblebeetkoeppe
authored andcommitted
CWG2899 Bad value representations should cause undefined behavior
1 parent 0b1cf18 commit 4c2bc49

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

source/expressions.tex

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,22 @@
674674
pointer value\iref{basic.stc.dynamic.deallocation}, the behavior is
675675
\impldef{lvalue-to-rvalue conversion of an invalid pointer value}.
676676

677+
\item Otherwise, if the bits in the value representation of
678+
the object to which the glvalue refers
679+
are not valid for the object's type, the behavior is undefined.
680+
\begin{example}
681+
\begin{codeblock}
682+
bool f() {
683+
bool b = true;
684+
char c = 42;
685+
memcpy(&b, &c, 1);
686+
return b; // undefined behavior if \tcode{42} is not a valid value representation for \keyword{bool}
687+
}
688+
\end{codeblock}
689+
\end{example}
690+
677691
\item Otherwise, the object indicated by the glvalue is read\iref{defns.access},
678692
and the value contained in the object is the prvalue result.
679-
If the result is an erroneous value\iref{basic.indet} and
680-
the bits in the value representation are not valid for the object's type,
681-
the behavior is undefined.
682693
\end{itemize}
683694

684695
\pnum

0 commit comments

Comments
 (0)