This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PING: [C++-11 PATCH] Trailing comma in enum


Could someone please review this?

On Sun, 2011-10-09 at 16:27 +0200, Magnus Fromreide wrote:
> Hi.
> 
> As I understand it C++-11 allows trailing commas in enum definitions.
> Thus I think the following little patch should be included.
> 
> /MF

2011-10-09 Magnus Fromreide <magfr@lysator.liu.se>
        * gcc/cp/parser.c (cp_parser_enumerator_list): Do not warn about
          trailing commas in C++11 mode.
        * gcc/testsuite/g++.dg/cpp0x/enum21a.C: Test that enum x { y, } do
          generate a pedwarning in c++98-mode.
        * gcc/testsuite/g++.dg/cpp0x/enum21b.C: Test that enum x { y, }
          don't generate a pedwarning in c++11-mode.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180624)
+++ gcc/cp/parser.c	(working copy)
@@ -14058,6 +14058,7 @@
 
    enum-specifier:
      enum-head { enumerator-list [opt] }
+     enum-head { enumerator-list , } [C++11]
 
    enum-head:
      enum-key identifier [opt] enum-base [opt]
@@ -14077,6 +14078,8 @@
    GNU Extensions:
      enum-key attributes[opt] identifier [opt] enum-base [opt] 
        { enumerator-list [opt] }attributes[opt]
+     enum-key attributes[opt] identifier [opt] enum-base [opt]
+       { enumerator-list , }attributes[opt] [C++11]
 
    Returns an ENUM_TYPE representing the enumeration, or NULL_TREE
    if the token stream isn't an enum-specifier after all.  */
@@ -14416,8 +14419,9 @@
       /* If the next token is a `}', there is a trailing comma.  */
       if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
 	{
-	  if (!in_system_header)
-	    pedwarn (input_location, OPT_pedantic, "comma at end of enumerator list");
+	  if (cxx_dialect < cxx0x && !in_system_header)
+	    pedwarn (input_location, OPT_pedantic,
+                     "comma at end of enumerator list");
 	  break;
 	}
     }
Index: gcc/testsuite/g++.dg/cpp0x/enum21a.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/enum21a.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/enum21a.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-pedantic-errors -std=c++98" }
+
+enum x { y, }; // { dg-error "comma at end of enumerator list" }
Index: gcc/testsuite/g++.dg/cpp0x/enum21b.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/enum21b.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/enum21b.C	(revision 0)
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "-pedantic-errors -std=c++0x" }
+
+enum x { y, };

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]