[Bug middle-end/92210] no warning for invariable used in loop condition (i.e. add clang's -Wfor-loop-analysis)

dcb314 at hotmail dot com gcc-bugzilla@gcc.gnu.org
Sat Aug 29 12:59:30 GMT 2020


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

--- Comment #5 from David Binderman <dcb314 at hotmail dot com> ---
Not only does clang detect that the control variable isn't changed,
it also detects when the control variable is changed too much.

Code like this gets warned:

for (int i = 0; i < 10; ++i)
{
 // whatever
 ++i;
}

aug29c.cc:9:5: warning: variable 'i' is incremented both in the loop header and
in the loop body [-Wfor-loop-analysis]
                ++i;
                  ^
aug29c.cc:6:28: note: incremented here
        for (int i = 0; i < 10; ++i)
                                  ^


More information about the Gcc-bugs mailing list