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

            Bug ID: 69686
           Summary: Useless -Wparentheses for A && B || !A && C
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wipedout at yandex dot ru
  Target Milestone: ---

I'm compiling this with gcc 5.3.0 with  -O3 -Wall -std=c++11

void test()
{
  int a, b, c;
  if(a && b || !a && c);
}

Please ignore the uninitialized variables. I get this warning:
warning: suggest parentheses around '&&' within '||' [-Wparentheses]

Okay, there're four ways to put them here:

Option one is repeating the default behavior
if((a && b) || (!a && c));

Option two is
if(a && (b || !a) && c);
Note "a && (b || !a)" part which is equivalent to "a && b || a && !a" which
contains "a && !a" which is always "false" and so makes no sense.

Option three is
if((a && b || !a) && c);
which now contains "a && b || !a" which makes no sense.

Option four is
if(a && (b || !a && c)); which contains the same nonsense as option two.

So here there's only once reasonable way to put parentheses and the warning is
useless.

Reply via email to