https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95673
Franz Sirl <sirl at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |sirl at gcc dot gnu.org --- Comment #5 from Franz Sirl <sirl at gcc dot gnu.org> --- Wstring-compare seems to depend a lot on the optimizations. In the following testcase warnings are also inconsistent and fragile (slight changes make the warning disappear): int c, d, e; void f(void) { const char *file = (c & 7) ? "file1234.txt" : "x"; const char *file2 = (c & 7) ? "y" : "file12.txt"; if (c == 2) if (d || __builtin_strcmp(file, "file123.txt") || __builtin_strcmp(file2, "file123.txt") ) e = 2; } With "gcc -c -O2 -Wstring-compare testcase.c" current trunk shows: testcase.c: In function 'f': testcase.c:8:12: warning: '__builtin_strcmp' of a string of length 11 and an array of size 11 evaluates to nonzero [-Wstring-compare] 8 | || __builtin_strcmp(file2, "file123.txt") | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There is no warning for line 7 ('file'). Maybe the warning could also be a bit more verbose when the information is available, like for example: warning: '__builtin_strcmp' of a string ('file2' with content "y" || "file12.txt") and an array ("file123.txt") of size 11 always evaluates to nonzero [-Wstring-compare]