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

--- Comment #3 from Ian Kirkham <Ian.Kirkham at brownandsticky dot net> ---
-Wparentheses is potentially very useful but certainly too broad.

I agree that it would help if qualifiers could be added that split the coverage
to be able to distinguish between the extremes of 'very probably not intended'
from the 'might make intent more explicit'.
The former class should include:

    if (mask & 1 == 1) ...

the latter class should include:

    if (var1 == 1 && var2 == 2 || var1 = 2 && var2 == 1) ...

At the moment -Wparentheses will flag both as needing parens to scope the &/&&
operator. However, I argue that the latter is at worst a stylistic error
because adding the parens as suggested will not change the effect of the code.

However in the former case, adding the parens will certainly change the effect
of the code as there is a very strong likelihood that the bit-wise AND was
expected to have a higher precedence than the comparison operators.

Perhaps the suggested -Woperator-precedence qualifier should be two:

-Wsafe-operator-precedence
    flagging all the operator precedence categories

-Woperator-precedence
    flagging just those where bitwise operators are at the same lexical scope
as a comparison operator.

Reply via email to