[Bug c/45610] New: misleading warning when && operator paired with a constant - is it operator precedence?

alexander dot stohr at gmx dot de gcc-bugzilla@gcc.gnu.org
Thu Sep 9 10:19:00 GMT 2010


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


-- 
           Summary: misleading warning when && operator paired with a
                    constant - is it operator precedence?
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexander dot stohr at gmx dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45610



More information about the Gcc-bugs mailing list