+2015-04-30 Marek Polacek <polacek@redhat.com>
+
+ * c-common.c (maybe_warn_bool_compare): When comparing with 0/1,
+ require that the non-constant be of a boolean type.
+
2015-04-29 Josh Triplett <josh@joshtriplett.org>
* c-common.c (handle_section_attribute): Refactor to reduce
}
else if (integer_zerop (cst) || integer_onep (cst))
{
+ /* If the non-constant operand isn't of a boolean type, we
+ don't want to warn here. */
+ tree noncst = TREE_CODE (op0) == INTEGER_CST ? op1 : op0;
+ /* Handle booleans promoted to integers. */
+ if (CONVERT_EXPR_P (noncst)
+ && TREE_TYPE (noncst) == integer_type_node
+ && TREE_CODE (TREE_TYPE (TREE_OPERAND (noncst, 0))) == BOOLEAN_TYPE)
+ /* Warn. */;
+ else if (TREE_CODE (TREE_TYPE (noncst)) != BOOLEAN_TYPE
+ && !truth_value_p (TREE_CODE (noncst)))
+ return;
/* Do some magic to get the right diagnostics. */
bool flag = TREE_CODE (op0) == INTEGER_CST;
flag = integer_zerop (cst) ? flag : !flag;