I had a hard time to find a bug in my code caused by a loop like this:
for (int i=i;i<5;i++){
// ...
}
I use g++ 4.7.2 with -O2 -Wall, but no warning/error is shown. Is there some compiler flag that also in combination with -O2 creates a warning for such a case?
I found several related questions:
here in the comments it is discussed, that g++ shows a warning with -Wall when there is no -O2. However, that question is particular because the problematic loop is optimized away with -O2 which would explain that no warning is shown. In my case the loop is not optimized away, but still I get no warning.
Also related is this question and this one. After reading those questions, I understand why c++ allows such non-sense (I like the example here because it isnt nonsense at all), but I am still looking for a compiler flag that would create a warning also with -O2.