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. > Also, having hardly any experience with the fixit hints, I'm not > sure how helpful this one is. It seems really hard to tell what > it suggests as the fix (I had to try it both ways to see). I > think would be a lot clearer if it showed the full expression > rather than just the operators. Would printing this instead be > doable? > > r = !a == (b | c); > ^~ > (!a) David answered this and I don't have a strong opinion on this. Marek