https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77436
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is undefined behavior and here is why: > Since the lower limit is the additive inverse of the upper limit, all summands > must cancel each other out and the result must be zero (this is still true > with > overflow) No that is not true. If you were adding ((-(INT_MAX-1)) + (INT_MAX-1)) + (-(INT_MAX-2)) + (INT_MAX-2) in that order, there would be no overflow but since you are adding in the following order: ((-(INT_MAX-1)) + (-(INT_MAX-2)) There is an overflow right away.