This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/69684] New: Useless -Wparentheses for A || !A && B


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

            Bug ID: 69684
           Summary: Useless -Wparentheses for A || !A && B
           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;
  if(a || !a && b);
}

Please ignore the uninitialized variables for now.

I get this warning emitted:
warning: suggest parentheses around '&&' within '||' [-Wparentheses]

There're two options of how to put parentheses here.

Option one is to repeat the default behavior:

if(a || (!a && b));

Option two is this:

if((a || !a) && b);

and then I have "always true" on the left hand of && which is likely not what
anyone would want. So option two makes no sense and there's only one reasonable
way to put parentheses in this code and so the suggestion is completely useless
in this code.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]