]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2016-10-07 Bernd Edlinger <bernd.edlinger@hotmail.de>
authoredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Oct 2016 17:10:38 +0000 (17:10 +0000)
committeredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Oct 2016 17:10:38 +0000 (17:10 +0000)
        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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240867 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wint-in-bool-context.c

index 7881233f94cd2898397920f104be75b3b4f47606..08535d0ba2b4365a2504ad1600ae59ebf0c19f20 100644 (file)
@@ -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
index f518c20797f53923fa4a0b68e0d29a63f5277203..19609a59d9ccce4a9575a054ec32e95aa6cf8e13 100644 (file)
@@ -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;
 
index f88e16da05a1267fe0b0feda72461664c5f3432a..085e0a53c3874a5aa9f3b527244da4574f0eb0b3 100644 (file)
@@ -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
index c2bd4421e14ec638ca3b2f7991b00f6b571f3c48..8728991af7393f74f959e1d8be5fe5dabe7a7001 100644 (file)
@@ -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.  */
index 1184d5cf14b2df59ea34f256b61cee3d54540d90..fd69779350aff07139c74d4165e6206ecde1e6ec 100644 (file)
@@ -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.
index 36daf546834dd486b9cedf0b29707346501b4e9a..42ff14784cc84b811b39f63cf7b9d45122fd6191 100644 (file)
@@ -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;
 }