[Bug c++/79373] For loop optimization bug: condition ignored

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 6 01:23:00 GMT 2017


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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Steven Pigeon from comment #7)
> I do understand that this is what happens (the code is fixed by promoting
> int32_t t=x to int64_t t=x) but the undefined behavior affects a variable
> (and its associated comparison) that should not be affected by it.

The C++ standards defines undefined behavior as "behavior for which this
International Standard imposes no requirements". No requirements. Not "doesn't
affect things that you think shouldn't be affected". All bets are off.

There is no requirement for a compiler to do something you find unsurprising,
or to limit the scope of the bug to parts of the code you expect to misbehave.


More information about the Gcc-bugs mailing list