What the GNU C Reference Guide means that you have two possible overflows. The first is the i++ operator in
for( i = INT_MAX - 10 ; i <= INT_MAX; i++)
and the second - i+1 in
if( i+1 < 0 )
C code example eliminates perpetual loop with
if( i+1 < 0 ) //first overflow { report_overflow(); break; }
and for that you rely on wrapparound signed behavior.
However, in Appendix A.3, you are informed that you should not rely on the signed wraparound behavior because the optimizer uses its undefined behavior and can generate code that will behave differently than you expect. This refers to the if( i+1 < 0 ) code snippet, which is supposed to bypass when i equals INT_MAX .
As a conclusion to the above code may fail after optimization by the compiler.
source share