Compiling the following code with gcc-4.3 -Wlogical-op -O1 int main () { char *s, t; strchr (s, t); } leads to this warning: test2.c: In function ‘main’: test2.c:7: warning: logical ‘&&’ with non-zero constant will always evaluate as true This is because libc defines strchr to a macro in bits/string.h. It looks to me like gcc should not warn about optimizations like __builtin_constant_p optimizations as those are diectly targeted at being optimized out.
Well also I think glibc should not need to optimise strchr really and let the compiler do it.
We need a reproducible preprocessed testcase. See http://gcc.gnu.org/bugs.html#detailed
Benjamin, note that -Wlogical-op will be enabled by -Wextra in GCC 4.5. I am willing to give it a try to fix this before 4.5 is released. However, I cannot reproduce this problem, so please, provide a preprocessed testcase.
I cannot reproduce this anymore with gcc 4.3.3 from Ubuntu 9.04, so I consider this fixed.
FIXED per previous comment.
I get this error when building swfdec with gcc 4.4.2 on Fedora 12.
Also tried the simple test case described in the bug description, although it needs to add #include <string.h> at the top. The warning is still there.
Created attachment 19148 [details] Preprocessed source file Created a preprocessed source file producing the warning.
(In reply to comment #6) > I get this error when building swfdec with gcc 4.4.2 on Fedora 12. It is a warning that you need to enable with -Wlogical-op explicitly. I cannot reproduce the preprocessed testcase with GCC 4.5 rev 150311. If you can reproduce it with a more recent revision, please let us know. Since this is not a regression (it was a new warning in GCC 4.3), I don't think anyone will try to fix it in GCC 4.3.x or GCC 4.4.x. Now that we have a preprocessed testcase, I will try to reduce it and add it to the testsuite to avoid regressing here.
Now that we have a preprocessed testcase, I will try to reduce it and add it to the testsuite to avoid regressing here.
Subject: Bug 36513 Author: manu Date: Fri Feb 19 21:21:34 2010 New Revision: 156912 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156912 Log: 2010-02-19 Manuel López-Ibáñez <manu@gcc.gnu.org> PR 36513 testsuite/ * c-c++-common/pr36513.c: New testcase. * c-c++-common/pr36513-2.c: New testcase. Added: trunk/gcc/testsuite/c-c++-common/pr36513-2.c trunk/gcc/testsuite/c-c++-common/pr36513.c Modified: trunk/gcc/testsuite/ChangeLog
FIXED in GCC 4.5