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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Eran Kornblau from comment #2)
> Thanks Andreas, I understand there's an overflow here, but isn't it a bug
> that it affects the second part of the condition?


No.


> I mean, any value is legit for the first part of the condition, if the
> behavior is undefined... but the second part of the condition is well
> defined. 


That's not how undefined behaviour works. If the program has undefined
behaviour, the entire program has undefined behaviour. The unexpected outcome
is not limited to a single expression.

> I personally find it a bit troubling that -
> 1. The result of the condition depends on the order of the operands (while
> they don't have any side-effects...), and -

They don't have side effects, but evaluating one condition might have undefined
behaviour, so it's up to you to avoid that.


> 2. The optimizations change the behavior of the code in this case

No, the behaviour is always undefined. Optimization changes the observed
outcomes of that undefined behaviour, but that's allowed. Undefined behaviour
means anything can happen.

"This undefined behaviour surprises me" is not a bug.

Reply via email to