diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2016-10-07 17:10:38 +0000 |
---|---|---|
committer | Bernd Edlinger <edlinger@gcc.gnu.org> | 2016-10-07 17:10:38 +0000 |
commit | c09c4992ac138656415fc108edcab8d643fc89bb (patch) | |
tree | 303ab8a08b00dcbd206ce3f14a8c4ed3752ff2c6 /gcc | |
parent | 125f0e39bfde6c0eb81a5409ce09112f4b875860 (diff) | |
download | gcc-c09c4992ac138656415fc108edcab8d643fc89bb.zip gcc-c09c4992ac138656415fc108edcab8d643fc89bb.tar.gz gcc-c09c4992ac138656415fc108edcab8d643fc89bb.tar.bz2 |
re PR c++/77700 (suspicios code in cp/parser.c)
2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de>
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 <bernd.edlinger@hotmail.de>
PR c++/77700
* parser.c (cp_parser_base_specifier): Fix a warning.
testsuite:
2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR c++/77700
* c-c++-common/Wint-in-bool-context.c: Update test.
From-SVN: r240867
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 5 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/parser.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wint-in-bool-context.c | 8 |
6 files changed, 30 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 7881233..08535d0 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de> + + PR c++/77700 + * c-common.c (c_common_truthvalue_conversion): Warn also for + suspicious enum values in boolean context. + 2016-10-06 Jakub Jelinek <jakub@redhat.com> Implement P0258R2 - helper for C++17 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f518c20..19609a5 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 f88e16d..085e0a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de> + + PR c++/77700 + * parser.c (cp_parser_base_specifier): Fix a warning. + 2016-10-07 Bernd Schmidt <bschmidt@redhat.com> PR c++/69733 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c2bd442..8728991 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 1184d5c..fd69779 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de> + + PR c++/77700 + * c-c++-common/Wint-in-bool-context.c: Update test. + 2016-10-07 Richard Biener <rguenther@suse.de> * 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 36daf54..42ff147 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; } |