[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 Marek Polacek changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org --- Comment #16 from Marek Polacek --- Fixed.
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #15 from Marek Polacek --- Author: mpolacek Date: Mon Aug 29 18:13:13 2016 New Revision: 239833 URL: https://gcc.gnu.org/viewcvs?rev=239833=gcc=rev Log: PR c/77292 * c-common.c (warn_logical_not_parentheses): Don't warn for a comparison or a logical operator. * c-c++-common/Wlogical-not-parentheses-1.c: New test. Added: trunk/gcc/testsuite/c-c++-common/Wlogical-not-parentheses-1.c Modified: trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c-common.c trunk/gcc/testsuite/ChangeLog
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #14 from Manuel López-Ibáñez --- (In reply to Manuel López-Ibáñez from comment #10) > > t.c:4:13: warning: logical not is only applied to the left hand side of > > comparison [-Wlogical-not-parentheses] > >return !a == (a < b); > > ^~ > > Why is this not a valid warning? Ah, this is on purpose to avoid too many false positives. Sorry for the noise.
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #13 from Segher Boessenkool --- (In reply to Manuel López-Ibáñez from comment #12) > (In reply to Segher Boessenkool from comment #11) > > Both of these suggestions are not so good. "!(a == b)" is better written > > as "a != b", and "!(a) == b" is just horrible. > > Agreed for the former, but the latter is suggesting (!a) == b, which is IMHO > clearer than ! a == b. Ah. The parens are placed suggestively around the "a" in the suggestion, so it is misleading even :-/ (Or maybe I'm just not very good at reading).
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #12 from Manuel López-Ibáñez --- (In reply to Segher Boessenkool from comment #11) > Both of these suggestions are not so good. "!(a == b)" is better written > as "a != b", and "!(a) == b" is just horrible. Agreed for the former, but the latter is suggesting (!a) == b, which is IMHO clearer than ! a == b.
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 Segher Boessenkool changed: What|Removed |Added CC||segher at gcc dot gnu.org --- Comment #11 from Segher Boessenkool --- (In reply to Manuel López-Ibáñez from comment #4) > Note that Clang suggests two ways to silence the warning: > > prog.cc:9:10: note: add parentheses after the '!' to evaluate the comparison > first > return !a == b; > ^ > ( ) > prog.cc:9:10: note: add parentheses around left hand side expression to > silence this warning > return !a == b; > ^ > ( ) Both of these suggestions are not so good. "!(a == b)" is better written as "a != b", and "!(a) == b" is just horrible.
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #10 from Manuel López-Ibáñez --- (In reply to Richard Biener from comment #5) > int > foo (int a, int b) > { > return !a == (a < b); > } > > t.c: In function ‘foo’: > t.c:4:13: warning: logical not is only applied to the left hand side of > comparison [-Wlogical-not-parentheses] >return !a == (a < b); > ^~ Why is this not a valid warning? #include void foo (int a, bool b) { printf("(!a) == b -> %d\n", (int) (!a) == b); printf("!(a == b) -> %d\n", (int) !(a == b)); } int main() { foo(2,1); } (!a) == b -> 0 !(a == b) -> 1
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #9 from Manuel López-Ibáñez --- (In reply to M Welinder from comment #3) > I am not aware of a rule that requires the compiler to ignore context > when considering warnings. It certainly does consider context when > it issues "might be used uninitialized" warnings, so why not here? Wuninitialized warnings are implemented in the middle-end. They benefit from the analysis done by optimization, but also suffer from the optimizations transforming and removing code (PR18501 and http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings). Warnings in the FE, like this one, are more consistent but there is very limited analysis done in the FE (because it is harder to implement in the FE, it may slow down the compiler and would duplicate the analysis done in the middle-end for optimization).
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #8 from Marek Polacek --- Neither does cc1plus because comparison result has a boolean type... I'll see what I can do here.
[Bug c/77292] Spurious warning: logical not is only applied to the left hand side of comparison
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 Richard Biener changed: What|Removed |Added Status|SUSPENDED |NEW Summary|value range propagation |Spurious warning: logical |(VRP) would improve |not is only applied to the |-Wlogical-not-parentheses |left hand side of ||comparison Known to fail||6.1.1 --- Comment #7 from Richard Biener --- Clang doesn't warn about this.
[Bug c/77292] Spurious "warning: logical not is only applied to the left hand side of comparison"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 --- Comment #3 from M Welinder --- The actual code I got this warning from was... if (!lower_tail == (p > phalf)) { where lower_tail is an int and p and phalf are doubles. That's simply a comparison of two booleans. Note, that the hinted-at code !(lower_tail == (p > phalf)) is dubious: comparing an int to a booleans. > this isn't visible to the compiler when it analyzes > return !a == b; I am not aware of a rule that requires the compiler to ignore context when considering warnings. It certainly does consider context when it issues "might be used uninitialized" warnings, so why not here?
[Bug c/77292] Spurious "warning: logical not is only applied to the left hand side of comparison"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 Marek Polacek changed: What|Removed |Added CC||mpolacek at gcc dot gnu.org --- Comment #2 from Marek Polacek --- Not a bug, IMHO.
[Bug c/77292] Spurious "warning: logical not is only applied to the left hand side of comparison"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292 Richard Biener changed: What|Removed |Added Keywords||diagnostic --- Comment #1 from Richard Biener --- Well, // Make it obvious that these are booleans. a = !!a; b = !!b; this isn't visible to the compiler when it analyzes return !a == b; to warn. Your example is very specific and unlike from real code so are you complaining about return !a == b; warning even when it is not immediately preceeded by a a = !!a; stmt? Then we've discussed this to death already.