https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53871
--- Comment #8 from David Binderman <dcb314 at hotmail dot com> --- (In reply to Andrew Pinski from comment #7) > The above loop is not so obvious an infinite loop at all. Since f2 is not > declared as pure/const, GCC can think the return value changes without the > argument changing. So the example in comment #6 is not an obvious example > :). I took out the if statement and gcc still can't detect the problem void f3() { int i = 0; do { int n = f2( i); } while (i < 8); } $ ~/gcc/results/bin/gcc -c -O2 -Wall -Wextra dec30b.cc dec30b.cc: In function ‘void f3()’: dec30b.cc:23:7: warning: unused variable ‘n’ [-Wunused-variable] int n = f2( i); ^ $ On the other hand, here is cppcheck detecting the problem: [dec30b.cc:24]: (style) Condition 'i<8' is always true