Commit 700fff34 by Bernd Edlinger Committed by Bernd Edlinger

c-common.c (c_common_truthvalue_conversion): Warn also for suspicious…

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
parent 17a9e380
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
......
......@@ -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 ())
......
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.
......
......@@ -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" } */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment