diff options
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wint-in-bool-context.c | 2 |
4 files changed, 19 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index d3c7cd5..2bfce86 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-10-05 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * c-common.c (c_common_truthvalue_conversion): Warn also for suspicious + conditional expression in boolean context when only one arm is + non-boolean. + 2016-10-05 Jakub Jelinek <jakub@redhat.com> PR sanitizer/77823 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index dbef199..035afbc 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4675,6 +4675,14 @@ c_common_truthvalue_conversion (location_t location, tree expr) warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, "?: using integer constants in boolean context, " "the expression will always evaluate to %<true%>"); + else if ((TREE_CODE (val1) == INTEGER_CST + && !integer_zerop (val1) + && !integer_onep (val1)) + || (TREE_CODE (val2) == INTEGER_CST + && !integer_zerop (val2) + && !integer_onep (val2))) + warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, + "?: using integer constants in boolean context"); } /* Distribute the conversion into the arms of a COND_EXPR. */ if (c_dialect_cxx ()) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c587f6..fa8cce7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-05 Bernd Edlinger <bernd.edlinger@hotmail.de> + + * c-c++-common/Wint-in-bool-context.c: Update test. + 2016-10-05 Marek Polacek <polacek@redhat.com> * g++.dg/cpp1z/init-statement1.C: New test. diff --git a/gcc/testsuite/c-c++-common/Wint-in-bool-context.c b/gcc/testsuite/c-c++-common/Wint-in-bool-context.c index 832eb0a..36daf54 100644 --- a/gcc/testsuite/c-c++-common/Wint-in-bool-context.c +++ b/gcc/testsuite/c-c++-common/Wint-in-bool-context.c @@ -10,7 +10,7 @@ int foo (int a, int b) if (a > 0 && a <= (b == 2) ? 1 : 1) /* { dg-bogus "boolean context" } */ return 2; - if (a > 0 && a <= (b == 3) ? 0 : 2) /* { dg-bogus "boolean context" } */ + if (a > 0 && a <= (b == 3) ? 0 : 2) /* { dg-warning "boolean context" } */ return 3; if (a == b ? 0 : 0) /* { dg-bogus "boolean context" } */ |