Re:A Guide to Undefined Behavior in C and C++
by gpderetta on Friday August 18, 2023 @06:03AM
(#37173513)
No, the compiler is proving that the return true statement must be executed given the axiom that the loop cannot overflow.
This is tricky, because the code is perfectly valid if it always early-exit (and I have written code like this myself that avoids bound checking by guaranteeing an early exit, when micro-optimizing), so it is hard to statically reject it. On the other hand it seems a very obvious thing to warn on.
This is tricky, because the code is perfectly valid if it always early-exit (and I have written code like this myself that avoids bound checking by guaranteeing an early exit, when micro-optimizing), so it is hard to statically reject it. On the other hand it seems a very obvious thing to warn on.