On Fri, Feb 20, 2015 at 04:35:05PM +0100, Marek Polacek wrote:
> Note that first version of -Wlogical-not-parentheses didn't warn
> when LHS had a boolean type, this has been changed later on.  I have
> no strong preference either way.
> 
> > As the argument is already folded, it isn't easy to determine
> > those cases always, but I hope the following is sufficient until we switch
> > to late folding.
>  
> Yes, this means that we warn for
> 
>   return !(a != 0) == b;
> 
> but not for
> 
>   return !(a == 0) == b;
> 
> I think we can live with that for now.

Well, for the !! case another option is, as we at least in the C++ FE
peek at the first token if it is !, peek another token if it is ! too.
Then we would warn for !(!a) == b and would not warn for !!a == b.
Guess that would be fine too.
For the ! of bool, if we want to detect that case (have done that primarily
because clang++ does that (clang doesn't support
-Wlogical-not-parentheses)), for C because of the conversion to int it is
still more likely we catch it, but for C++ we'd need to parse the expression
twice or do similar uglities.
For everything the answer is of course less folding early, but it will take
some time.

> The C part is ok.  Maybe we should also update the docs to reflect that
> -Wlogical-not-parentheses does not warn if the RHS *or LHS* operand is of
> a boolean type.  Thanks,

RHS operand or operand of ! on the LHS to be precise, though that is not
what is implemented for C++ right now, e.g. !(a > 20) == 0 shouldn't warn
in C++ because a > 20 is bool, but it is really hard after the folding to
find out what was the original ! operand.
Though of course, it would be weird if we don't warn for !(a > 20) == 0
for C (where a > 20 is not _Bool) but do warn for C++ (where it is bool).

If preferred, I can do just the !! case that in theory should be reliably
detected, and warn for everything else.

        Jakub

Reply via email to