The expressions (z & 2) == 4 and (z | 2) == 4 are always false. When these appear in programs it is almost always unintended, but gcc fails to warn the user. An example undiagnosed mistake appears in gcc/gcc/java/parse.y near line 1154 /* Can't have a static initializer in an innerclass */ if ($1 | ACC_STATIC && ... The '|' is unlikely to have been intended. I added a warning for this to "my" gcc years ago, and it works well. I recently got this warning added to the Java "findbugs" tool http://findbugs.sourceforge.net/bugDescriptions.html (That took less than a week, in stark contrast to my experiences with gcc). I have a patch, but this web form lacks a way to supply it.
Created attachment 7179 [details] proposed patch
Hmm, I think I thought I saw this somewhere else. Confirmed.
Re: "think I thought I saw this somewhere else". This patch includes a fix for previously reported PR 16632. That has gone nowhere so I decided to report the enhancement that I actually want.
Created attachment 7285 [details] revised patch The fix for PR 16632 invalidates the previously proposed patch. Here is new one.
Since fold() is increasingly used for internal speculative computations, I think it should avoid issuing warnings as false positives are too likely. So perhaps this warning belongs in parser_build_binary_op() in c-typeck.c Similarly for bug 16302
Still an issue with revision 180166. This could be warned by Wlogical-op.
*** Bug 59491 has been marked as a duplicate of this bug. ***
*** Bug 65423 has been marked as a duplicate of this bug. ***
*** Bug 46582 has been marked as a duplicate of this bug. ***
Fixed for GCC 6 by r6-2453-g05b28fd6f91016 (aka PR 66555) so just marking as a dup of that bug. *** This bug has been marked as a duplicate of bug 66555 ***