This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]