[PATCH] New warning for mismatch between not and and/or operators.

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Mon Oct 13 18:55:38 PDT 2014


Test cases?

>Examples:
>int x = ~y | ~z;
>Fixed with | => ||

The code `~y | ~z` looks reasonable to me. It's equivalent to `~(y & z)`, a.k.a. "all the flags that aren't part of either `y` or `z`".
Did you mean to denigrate `!y | !z` instead? In //that// case, the fixit `|` => `||` would definitely be appropriate IMHO.

>bool a = ~b && !c
>Fixed with ~b => !b

I wouldn't expect the compiler to suggest a fixit in this case, but if it did, this code is sufficiently confusing that I personally would rather see the compiler suggest `~b` => `(b != -1)`, rather than suggesting a fixit that quietly changes the meaning of the code.

http://reviews.llvm.org/D5765






More information about the cfe-commits mailing list