https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119005
Bug ID: 119005 Summary: -Wstrict-overflow=3 false positive with static variable Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: alx at kernel dot org Target Milestone: --- alx@debian:~/tmp$ cat foo.c #include <limits.h> int f(void) { static int i = 0; if (++i >= 3) return -1; return 0; } alx@debian:~/tmp$ gcc -Wall -Wstrict-overflow=3 -S foo.c foo.c: In function âfâ: foo.c:11:1: warning: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1 [-Wstrict-overflow] 11 | } | ^ GCC is not taking into account that the variable is static, and thus in the third call to this function the conditional will change its value. I think this shouldn't be warned. Or am I missing something?