http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56956

--- Comment #5 from Dan Gohman <sunfish at google dot com> 2013-04-15 05:12:30 
UTC ---
(In reply to comment #4)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > I think 'x' can not present negative value.
> > 
> > The unary minus operator is defined for unsigned types. It doesn't produce
> > signed overflow.
> 
> According to C99 6.5.3.3 Point 3 and C99 6.5 Point 5:
> 
> "The result of the unary '-' operator is the negative of its operand."
> 
> "... if the result is ... not in the range of representable
>  values for its type... the behavior is undefined."
> 
> So my understanding is that the evaluation expression '-x' is not
> a representable value of 'uint64_t', which is undefined behavior,
> resulting abort if -ftrav is issued.
> 
> Perhaps my understanding is incorrect? :(

Yes; unsigned types are an exception to the rule:

C99 6.2.5p9 says "A computation involving unsigned operands can never overflow,
because a result that cannot be represented by the resulting unsigned integer
type is reduced modulo the number that is one greater than the largest value
that can be represented by the resulting type."

The wording is a little vague, but it means that negative results are converted
to unsigned values by conceptually adding the maximum unsigned value plus one
until the value is in range.

Reply via email to