Hi,

this issue is about some enumeration types which are strictly speaking illegal and we are accepting nonetheless:

enum {}; //-std=c++98 or -std=c++11

enum class {}; //-std=c++11

enum class { x }; //-std=c++11

I suppose we want to be less strict about the former thus I'm using a pedwarn instead of an error. Not sure about the best wording of the warning/error messages.

Anyway, luckily only one existing testcase needs adjusting, I thought we had many, in the library too (in fact now I seem to remember I fixed some anonymous enum uses)

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////////



/cp
2013-04-10  Paolo Carlini  <paolo.carl...@oracle.com>

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

/testsuite
2013-04-10  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/54216
        * g++.dg/cpp0x/enum26.C: New.
        * g++.old-deja/g++.pt/mangle1.C: Adjust.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 197665)
+++ cp/parser.c (working copy)
@@ -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: testsuite/g++.dg/cpp0x/enum26.C
===================================================================
--- testsuite/g++.dg/cpp0x/enum26.C     (revision 0)
+++ testsuite/g++.dg/cpp0x/enum26.C     (working copy)
@@ -0,0 +1,8 @@
+// PR c++/54216
+// { dg-options "-std=c++11 -pedantic" }
+
+enum {};            // { dg-message "empty anonymous" }
+
+enum class {};      // { dg-error "anonymous" }
+
+enum class { x };   // { dg-error "anonymous" }
Index: testsuite/g++.old-deja/g++.pt/mangle1.C
===================================================================
--- testsuite/g++.old-deja/g++.pt/mangle1.C     (revision 197665)
+++ testsuite/g++.old-deja/g++.pt/mangle1.C     (working copy)
@@ -1,4 +1,5 @@
 // { dg-do assemble  }
+// { dg-options "" }
 // Origin: Mark Mitchell <m...@codesourcery.com>
 
 typedef enum {} i;

Reply via email to