[Bug c++/69684] New: Useless -Wparentheses for A || !A && B
wipedout at yandex dot ru
gcc-bugzilla@gcc.gnu.org
Fri Feb 5 08:29:00 GMT 2016
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.
More information about the Gcc-bugs
mailing list