On 09/05/16 16:28, Marek Polacek wrote: > On Mon, Sep 05, 2016 at 02:08:20PM +0000, Bernd Edlinger wrote: >> On 09/05/16 14:03, Marek Polacek wrote: >>> On Fri, Sep 02, 2016 at 03:51:49PM +0000, Bernd Edlinger wrote: >>>> Hi, >>>> >>>> > + r += !a == ~b; >>>> > + r += !a == ~(int) b; >>>> >>>> I don't understand why ~b should not be warned at -Wall. >>> >>> Yeah, there was an RFE for this but I'm not finding it. >>> >> >> I certainly agree that the warning is compeletely misleading here: >> >> test.c: In function 'f': >> test.c:10:11: warning: logical not is only applied to the left hand side >> of comparison [-Wlogical-not-parentheses] >> r += !a == ~b; >> ^~ >> test.c:10:8: note: add parentheses around left hand side expression to >> silence this warning >> r += !a == ~b; >> ^~ >> ( ) >> >> this will not fix it, but make it worse. >> I think a better warning would be >> warning: ~ on boolean value, did you mean ! ? > > Could you please open a PR? I'll take care of it. >
Done, thanks: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77490 > Still not sure about other operations. I guess no one would > object to warning on bool1 % bool2, but should we warn for > bool1 + bool2? > Yeah, any % bool is just blandly insane. Please add a warning for that as well. Not totally sure what to do about bool + bool: If it is *not* used in boolean context it's probably OK, but in boolean context why not use | instead? Note: we even optimize unary - in boolean context: see c-family/c-common.c (c_common_truthvalue_conversion): case NEGATE_EXPR: case ABS_EXPR: case FLOAT_EXPR: case EXCESS_PRECISION_EXPR: /* These don't change whether an object is nonzero or zero. */ return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); I wonder why there is no warning for NEGATE_EXPR and ABS_EXPR. Bernd.