re PR c++/54216 (Missing diagnostic for ill-formed anonymous enum declarations)
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 11 Apr 2013 09:01:24 +0000 (09:01 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 11 Apr 2013 09:01:24 +0000 (09:01 +0000)
/cp
2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/54216
* parser.c (cp_parser_enum_specifier): Check for empty
anonymous enums and anonymous scoped enums.

/testsuite
2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/54216
* g++.dg/cpp0x/enum26.C: New.
* g++.old-deja/g++.pt/mangle1.C: Adjust.

From-SVN: r197742

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/enum26.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.pt/mangle1.C

index 767b2c3820e9d41cb2a9f12ca1ae57a4898deca5..8d0f6c13b1c054b744f44e51d98e9839244494a9 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/54216
+       * parser.c (cp_parser_enum_specifier): Check for empty
+       anonymous enums and anonymous scoped enums.
+
 2013-04-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/56895
index 856dc9a85e3ee6dbea56b285f44f6adabdb5611a..e015c4f3540ff919b4cf2762d513fd1a19938388 100644 (file)
@@ -14750,6 +14750,9 @@ cp_parser_enum_specifier (cp_parser* parser)
        {
          identifier = make_anon_name ();
          is_anonymous = true;
+         if (scoped_enum_p)
+           error_at (type_start_token->location,
+                     "anonymous scoped enum is not allowed");
        }
     }
   pop_deferring_access_checks ();
@@ -14897,7 +14900,13 @@ cp_parser_enum_specifier (cp_parser* parser)
       if (type == error_mark_node)
        cp_parser_skip_to_end_of_block_or_statement (parser);
       /* If the next token is not '}', then there are some enumerators.  */
-      else if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
+      else if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
+       {
+         if (is_anonymous && !scoped_enum_p)
+           pedwarn (type_start_token->location, OPT_Wpedantic,
+                    "ISO C++ forbids empty anonymous enum");
+       }
+      else
        cp_parser_enumerator_list (parser, type);
 
       /* Consume the final '}'.  */
index abe23e239f765ddbe40e41ab736f127dd63a370d..943be90c9245b17321072cfbd15b1a2b50f4a63a 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/54216
+       * g++.dg/cpp0x/enum26.C: New.
+       * g++.old-deja/g++.pt/mangle1.C: Adjust.
+
 2013-04-11  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * gcc.target/aarch64/vect-fcm.x: Add check for zero forms of
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum26.C b/gcc/testsuite/g++.dg/cpp0x/enum26.C
new file mode 100644 (file)
index 0000000..a21067e
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/54216
+// { dg-options "-std=c++11 -pedantic" }
+
+enum {};            // { dg-warning "empty anonymous" }
+
+enum class {};      // { dg-error "anonymous" }
+
+enum class { x };   // { dg-error "anonymous" }
index d7be4fbf0fd7d057936257e8804c8780178432db..1fe009dbffcb08aa4b1c79850854926dec4ff9e5 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do assemble  }
+// { dg-options "" }
 // Origin: Mark Mitchell <mark@codesourcery.com>
 
 typedef enum {} i;