Skip to content

Commit

Permalink
CWG 1787 NB GB-2 Uninitialized unsigned char values.
Browse files Browse the repository at this point in the history
Removed second and subsequent references to [basic.fundamental] for
definition of unsigned narrow character type.
  • Loading branch information
zygoloid authored and Stefanus Du Toit committed Feb 23, 2014
1 parent aa83ed2 commit 426888a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 23 deletions.
4 changes: 2 additions & 2 deletions source/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@
\grammarterm{initializer} (if any), except as noted below. \enterexample

\begin{codeblock}
int x = 12;
{ int x = x; }
unsigned char x = 12;
{ unsigned char x = x; }
\end{codeblock}

Here the second \tcode{x} is initialized with its own (indeterminate)
Expand Down
13 changes: 0 additions & 13 deletions source/conversions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@
pointer value~(\ref{basic.stc.dynamic.deallocation},
\ref{basic.stc.dynamic.safety}), the behavior is implementation-defined.

\item Otherwise, if \tcode{T} is a (possibly cv-qualified) unsigned character
type~(\ref{basic.fundamental}), and the object to which the glvalue refers
contains an indeterminate value~(\ref{expr.new}, \ref{dcl.init},
\ref{class.base.init}), and that object does not have automatic storage
duration or the glvalue was the operand of a unary \tcode{\&} operator or it
was bound to a reference, the result is an unspecified value.\footnote{The
value may be different each time the lvalue-to-rvalue conversion is applied to
the object. An \tcode{unsigned char} object with indeterminate value allocated
to a register might trap.}

\item Otherwise, if the object to which the glvalue refers contains an
indeterminate value, the behavior is undefined.

\item Otherwise, the value contained in the object indicated by the
glvalue is the prvalue result.

Expand Down
51 changes: 47 additions & 4 deletions source/declarators.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2601,12 +2601,55 @@
\exitnote

\pnum
If no initializer is specified for an object, the object is default-initialized;
if no initialization is performed, an object
with automatic or dynamic storage duration
has indeterminate value.
\indextext{value!indeterminate}%
\indextext{indeterminate~value}%
If no initializer is specified for an object, the object is default-initialized.
When storage for an object with automatic or dynamic storage duration
is obtained, the object has an \term{indeterminate value}, and if
no initialization is performed for the object, that object retains an
indeterminate value until that value is replaced~(\ref{expr.ass}).
\enternote Objects with static or thread storage duration are zero-initialized,
see~\ref{basic.start.init}. \exitnote
If an indeterminate value is produced by an evaluation, the behavior is
undefined except in the following cases:

\begin{itemize}
\item
If an indeterminate value of unsigned narrow character
type~(\ref{basic.fundamental}) is produced by the evaluation of:
\begin{itemize}
\item the second or third operand of a conditional expression~(\ref{expr.cond}),
\item the right operand of a comma~(\ref{expr.comma}),
\item the operand of a cast or conversion to an unsigned narrow character
type~(\ref{conv.integral}, \ref{expr.type.conv}, \ref{expr.static.cast},
\ref{expr.cast}), or
\item a discarded-value expression (Clause~\ref{expr}),
\end{itemize}
then the result of the operation is an indeterminate value.

\item
If an indeterminate value of unsigned narrow character
type is produced by the evaluation of the right
operand of a simple assignment operator~(\ref{expr.ass}) whose first operand
is an lvalue of unsigned narrow character type, an indeterminate value replaces
the value of the object referred to by the left operand.

\item
If an indeterminate value of unsigned narrow character type is produced by the
evaluation of the initialization expression when initializing an object of
unsigned narrow character type, that object is initialized to an indeterminate
value.
\end{itemize}
\enterexample
\begin{codeblock}
int f(bool b) {
unsigned char c;
unsigned char d = c; // OK, d has an indeterminate value
int e = d; // undefined behavior
return b ? d : 0; // undefined behavior if b is true
}
\end{codeblock}
\exitexample

\pnum
\indextext{initialization!class~member}%
Expand Down
4 changes: 2 additions & 2 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3138,8 +3138,8 @@

\begin{itemize}
\item If the \grammarterm{new-initializer} is omitted, the object is
default-initialized~(\ref{dcl.init}); if no initialization is performed, the
object has indeterminate value.
default-initialized~(\ref{dcl.init}). \enternote If no initialization
is performed, the object has an indeterminate value. \exitnote

\item Otherwise, the \grammarterm{new-initializer} is interpreted according to
the initialization rules of~\ref{dcl.init} for direct-initialization.
Expand Down
9 changes: 7 additions & 2 deletions source/special.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1728,14 +1728,19 @@
program ill-formed.
\indextext{initialization!const member}%
\indextext{initialization!reference member}%
\enternote
After the call to a constructor for class
\tcode{X}
has completed, if a member of
for an object with automatic or dynamic storage duration
has completed, if
the constructor was not invoked as part of value-initialization and
a member of
\tcode{X}
is neither initialized nor
given a value
during execution of the \grammarterm{compound-statement} of the body of the constructor,
the member has indeterminate value.
the member has an indeterminate value.
\exitnote
\enterexample
\begin{codeblock}
struct A {
Expand Down

0 comments on commit 426888a

Please sign in to comment.