https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79919
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- There also is no option to control this warning, and outside of pr16302.{C,c} no tests for it. It seems that a good option to put this warning under might be -Wlogical-op. The text of the warning could also be made consistent with that issued by the option, i.e., like so (copied from c-family/c-warn.c): if (or_op) warning_at (location, OPT_Wlogical_op, "logical %<or%> of collectively exhaustive tests is " "always true"); else warning_at (location, OPT_Wlogical_op, "logical %<and%> of mutually exclusive tests is " "always false"); The implementation of the warning issued for the test case is in fold-const.c: /* Handle the case of comparisons with constants. If there is something in common between the masks, those bits of the constants must be the same. If not, the condition is always false. Test for this to avoid generating incorrect code below. */ result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask); if (! integer_zerop (result) && simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const), const_binop (BIT_AND_EXPR, result, r_const)) != 1) { if (wanted_code == NE_EXPR) { warning (0, "%<or%> of unmatched not-equal tests is always 1"); return constant_boolean_node (true, truth_type); } else { warning (0, "%<and%> of mutually exclusive equal-tests is always 0"); return constant_boolean_node (false, truth_type); } }