aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2014-08-19 18:50:00 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-08-19 18:50:00 +0000
commit04159acfd818cbc29a9d12dfa2e83716c106f2c7 (patch)
treec01c9d77dc28f6a4d017760a2f0f57809574d010 /gcc/c
parent8a2e8325e4b35265ea983561eca4a23a13630b07 (diff)
downloadgcc-04159acfd818cbc29a9d12dfa2e83716c106f2c7.zip
gcc-04159acfd818cbc29a9d12dfa2e83716c106f2c7.tar.gz
gcc-04159acfd818cbc29a9d12dfa2e83716c106f2c7.tar.bz2
re PR c++/62153 (warn for bool expression compared with integer different from 0/1)
PR c++/62153 * doc/invoke.texi: Document -Wbool-compare. c-family/ * c-common.c (maybe_warn_bool_compare): New function. * c-common.h (maybe_warn_bool_compare): Declare. * c.opt (Wbool-compare): New option. c/ * c-typeck.c (build_binary_op): If either operand of a comparison is a boolean expression, call maybe_warn_bool_compare. cp/ * call.c (build_new_op_1): Remember the type of arguments for a comparison. If either operand of a comparison is a boolean expression, call maybe_warn_bool_compare. testsuite/ * c-c++-common/Wbool-compare-1.c: New test. From-SVN: r214183
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c10
2 files changed, 16 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 391cfed..e5429ac 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2014-08-19 Marek Polacek <polacek@redhat.com>
+
+ PR c++/62153
+ * c-typeck.c (build_binary_op): If either operand of a comparison
+ is a boolean expression, call maybe_warn_bool_compare.
+
2014-08-19 Patrick Palka <ppalka@gcc.gnu.org>
PR c/45584
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 3210f1a..d6d96cf 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10679,6 +10679,11 @@ build_binary_op (location_t location, enum tree_code code,
result_type = type1;
pedwarn (location, 0, "comparison between pointer and integer");
}
+ if ((TREE_CODE (TREE_TYPE (orig_op0)) == BOOLEAN_TYPE
+ || truth_value_p (TREE_CODE (orig_op0)))
+ ^ (TREE_CODE (TREE_TYPE (orig_op1)) == BOOLEAN_TYPE
+ || truth_value_p (TREE_CODE (orig_op1))))
+ maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
break;
case LE_EXPR:
@@ -10783,6 +10788,11 @@ build_binary_op (location_t location, enum tree_code code,
result_type = type1;
pedwarn (location, 0, "comparison between pointer and integer");
}
+ if ((TREE_CODE (TREE_TYPE (orig_op0)) == BOOLEAN_TYPE
+ || truth_value_p (TREE_CODE (orig_op0)))
+ ^ (TREE_CODE (TREE_TYPE (orig_op1)) == BOOLEAN_TYPE
+ || truth_value_p (TREE_CODE (orig_op1))))
+ maybe_warn_bool_compare (location, code, orig_op0, orig_op1);
break;
default: