https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93301

Vincent Lefèvre <vincent-gcc at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vincent-gcc at vinc17 dot net

--- Comment #14 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to rguent...@suse.de from comment #10)
> I'd say "using" an uninitialized value is UB.

In general, but not for unsigned char. C17 6.2.4p6 says for objects with
automatic storage duration (which is the case here): "The initial value of the
object is indeterminate." 3.19.2 says "indeterminate value: either an
unspecified value or a trap representation". Since we have an unsigned char
here, this is not a trap representation. Thus this is an unspecified value.
3.19.3 says "unspecified value: valid value of the relevant type where this
International Standard imposes no requirements on which value is chosen in any
instance" (and the note says that this "cannot be a trap representation").

In short, by reading such an uninitialized unsigned char variable, you get a
valid value, but you don't know which one. And by reading the variable again,
you still get a valid value, which may be different. No UB here.

Reply via email to