From c09c4992ac138656415fc108edcab8d643fc89bb Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Fri, 7 Oct 2016 17:10:38 +0000 Subject: [PATCH] re PR c++/77700 (suspicios code in cp/parser.c) 2016-10-07 Bernd Edlinger PR c++/77700 * c-common.c (c_common_truthvalue_conversion): Warn also for suspicious enum values in boolean context. cp: 2016-10-07 Bernd Edlinger PR c++/77700 * parser.c (cp_parser_base_specifier): Fix a warning. testsuite: 2016-10-07 Bernd Edlinger PR c++/77700 * c-c++-common/Wint-in-bool-context.c: Update test. From-SVN: r240867 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 5 +++++ gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/Wint-in-bool-context.c | 8 ++++++++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 7881233f94c..08535d0ba2b 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-10-07 Bernd Edlinger + + PR c++/77700 + * c-common.c (c_common_truthvalue_conversion): Warn also for + suspicious enum values in boolean context. + 2016-10-06 Jakub Jelinek Implement P0258R2 - helper for C++17 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f518c20797f..19609a59d9c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4590,6 +4590,11 @@ c_common_truthvalue_conversion (location_t location, tree expr) return expr; case INTEGER_CST: + if (TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE + && !integer_zerop (expr) + && !integer_onep (expr)) + warning_at (location, OPT_Wint_in_bool_context, + "enum constant in boolean context"); return integer_zerop (expr) ? truthvalue_false_node : truthvalue_true_node; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f88e16da05a..085e0a53c38 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-10-07 Bernd Edlinger + + PR c++/77700 + * parser.c (cp_parser_base_specifier): Fix a warning. + 2016-10-07 Bernd Schmidt PR c++/69733 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c2bd4421e14..8728991af73 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -23338,7 +23338,7 @@ cp_parser_base_specifier (cp_parser* parser) cp_parser_nested_name_specifier_opt (parser, /*typename_keyword_p=*/true, /*check_dependency_p=*/true, - typename_type, + /*type_p=*/true, /*is_declaration=*/true); /* If the base class is given by a qualified name, assume that names we see are type names or templates, as appropriate. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1184d5cf14b..fd69779350a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-07 Bernd Edlinger + + PR c++/77700 + * c-c++-common/Wint-in-bool-context.c: Update test. + 2016-10-07 Richard Biener * gcc.dg/tree-ssa/vrp01.c: Adjust. 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 36daf546834..42ff14784cc 100644 --- a/gcc/testsuite/c-c++-common/Wint-in-bool-context.c +++ b/gcc/testsuite/c-c++-common/Wint-in-bool-context.c @@ -2,6 +2,8 @@ /* { dg-options "-Wint-in-bool-context" } */ /* { dg-do compile } */ +enum truth { yes, no, maybe }; + int foo (int a, int b) { if (a > 0 && a <= (b == 1) ? 1 : 2) /* { dg-warning "boolean context" } */ @@ -27,5 +29,11 @@ int foo (int a, int b) for (a = 0; 1 << a; a++); /* { dg-warning "boolean context" } */ + if (yes || no || maybe) /* { dg-warning "boolean context" "" { target c++ } } */ + return 8; + + if (yes || no) /* { dg-bogus "boolean context" } */ + return 9; + return 0; } -- 2.30.2