diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2016-10-05 18:34:17 +0000 |
---|---|---|
committer | Bernd Edlinger <edlinger@gcc.gnu.org> | 2016-10-05 18:34:17 +0000 |
commit | 700fff34d219e33b11fa63ac95bc524180781803 (patch) | |
tree | b1f72734e1bae5fc845deed7efc5b779061235be /gcc | |
parent | 17a9e3802a32f39707a2ac260f8f97b665a44c87 (diff) | |
download | gcc-700fff34d219e33b11fa63ac95bc524180781803.zip gcc-700fff34d219e33b11fa63ac95bc524180781803.tar.gz gcc-700fff34d219e33b11fa63ac95bc524180781803.tar.bz2 |
c-common.c (c_common_truthvalue_conversion): Warn also for suspicious conditional expression in boolean context when...
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.
testsuite:
2016-10-05 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-c++-common/Wint-in-bool-context.c: Update test.
From-SVN: r240799
Diffstat (limited to 'gcc')
-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" } */ |