On 08/26/2016 07:44 AM, Marek Polacek wrote:
On Thu, Aug 25, 2016 at 11:35:53AM -0600, Martin Sebor wrote:
+foo (int a, int b)
+{
+  int r = 0;
+  r += !a == (a < b);
+  r += !a == (a > b);
+  r += !a == (a >= b);
+  r += !a == (a <= b);
+  r += !a == (a != b);
+  r += !a == (a == b);
+  r += !a == (a || b);
+  r += !a == (a && b);
+  r += !a == (!b);
+
+  r += !a == (a ^ b); /* { dg-warning "logical not is only applied to the left hand 
side of comparison" } */
+  r += !a == (a | b); /* { dg-warning "logical not is only applied to the left hand 
side of comparison" } */
+  r += !a == (a & b); /* { dg-warning "logical not is only applied to the left hand 
side of comparison" } */

A question more than a comment: warning on the last three expressions
above makes sense to me when the operands are integers but I'm less
sure that the same logic applies when the operands are Boolean.  Does
it make sense to issue the warning for those given that (a | b) and
(a & b) are the same as (a || b) and (a && b) for which the warning
is suppressed?

In other words, is warning on the latter of the two below but not on
the former a good idea or should they be treated the same way?

I gave this a shot but it seems to be quite complicated, and I'm not
sure if it's worth the effort.  If you want, open a BZ and I'll look
into this later.

I opened bug 77423 for this.

Martin

Reply via email to