[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Aug 19 12:04:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292

--- Comment #10 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #5)
> int
> foo (int a, int b)
> {
>   return !a == (a < b);
> }
> 
> t.c: In function ‘foo’:
> t.c:4:13: warning: logical not is only applied to the left hand side of
> comparison [-Wlogical-not-parentheses]
>    return !a == (a < b);
>              ^~

Why is this not a valid warning?

#include <stdio.h>
void
foo (int a, bool b)
{
  printf("(!a) == b -> %d\n", (int) (!a) == b);
  printf("!(a == b) -> %d\n", (int) !(a == b));
}

int main()
{
    foo(2,1);
}

(!a) == b -> 0
!(a == b) -> 1


More information about the Gcc-bugs mailing list