gcc --version gcc (GCC) 4.3.1 Copyright (C) 2008 Free Software Foundation, Inc. found in package cairo-1.9.14 and file test/cairo-test.c with critical line 1597: if (ctx->thread == 0 && ! RUNNING_ON_VALGRIND) build outputs: "warning: logical '&&' with non-zero constant will always evaluate as true" from the used setup the VALGRIND macro is assumed to have a true value. (a code checker would probably suggest using round braces around the "==" part. the used default project tuning of gcc does not raise a warning on operator precedence.) whats the problem? a) if you use && with a constant and something else then your result will always either be false (const=false) or something else (const=true). there is no case for the compiler seeing this as fixed to true. b) maybe its unintended operator precedence that makes the case behave strangely
Subject: Re: New: misleading warning when && operator paired with a constant - is it operator precedence? You don't give a self-contained testcase whose behavior with different versions can be compared, but the warnings now are if (or_op) warning_at (location, OPT_Wlogical_op, "logical %<or%>" " applied to non-boolean constant"); else warning_at (location, OPT_Wlogical_op, "logical %<and%>" " applied to non-boolean constant"); and the reason is /* Warn if &&/|| are being used in a context where it is likely that the bitwise equivalent was intended by the programmer. That is, an expression such as op && MASK where op should not be any boolean expression, nor a constant, and mask seems to be a non-boolean integer constant. */
We need a testcase http://gcc.gnu.org/bugs/minimize.html but I am pretty sure this is not warned anymore in GCC 4.6 (and probably GCC 4.4 and 4.5)
Thus should be fixed.