On Mon, 2 Jun 2014, Marek Polacek wrote:
>       * c-typeck.c (parser_build_binary_op): Warn when logical not is used
>       on the left hand side operand of a comparison. 

This...

> +/* Warn about logical not used on the left hand side operand of a comparison.

...and this...

> +  warning_at (location, OPT_Wlogical_not_parentheses,
> +           "logical not is only applied to the left hand side of "
> +           "comparison");

...does not appear consistent with the actual warning.

Why does that warning say "is _ONLY_ applied to the left hand side"?

Based on the message, I naively assumed that the code should not warn
about

  int same(int a, int b) {
    return !a == !b;
  }

alas this is not the case.  (Code like this occurs in Wine where
bool types are emulated and !!a or a comparison like above ensure
that those emulated bools are normalized to either 0 or 1.)


I understand there is ambiguity in cases like

  return !a == b;

where the warning would be approriately worded and the programmer
might have intended !(a == b).


I do recommend to either omit "only" from the text of the warning
or not warn for cases where ! occurs on both sides of the comparison
(and keep the text as is).

Gerald

Reply via email to