public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: PING: [C++-11 PATCH] Trailing comma in enum
@ 2011-10-29 19:07 Ville Voutilainen
  2011-10-30 14:35 ` Magnus Fromreide
  0 siblings, 1 reply; 4+ messages in thread
From: Ville Voutilainen @ 2011-10-29 19:07 UTC (permalink / raw)
  To: magfr, gcc-patches

>Could someone please review this?

+	  if (cxx_dialect < cxx0x && !in_system_header)
+	    pedwarn (input_location, OPT_pedantic,
+                     "comma at end of enumerator list");

Why not use maybe_warn_cpp0x there?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PING: [C++-11 PATCH] Trailing comma in enum
  2011-10-29 19:07 PING: [C++-11 PATCH] Trailing comma in enum Ville Voutilainen
@ 2011-10-30 14:35 ` Magnus Fromreide
  2011-10-30 16:37   ` Ville Voutilainen
  0 siblings, 1 reply; 4+ messages in thread
From: Magnus Fromreide @ 2011-10-30 14:35 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 835 bytes --]

On Sat, 2011-10-29 at 20:48 +0300, Ville Voutilainen wrote:
> >Could someone please review this?
> 
> +	  if (cxx_dialect < cxx0x && !in_system_header)
> +	    pedwarn (input_location, OPT_pedantic,
> +                     "comma at end of enumerator list");
> 
> Why not use maybe_warn_cpp0x there?

maybe_warn_cpp0x seems to handle cases were C++11 extensions are used
but in this case a GNU extension is adopted by the standard so I wanted
to make a minimal change.

Attached is a variation where maybe_warn_cpp0x is used.

Please note how my new pedwarn breaks the pattern in maybe_warn_cpp0x.

One could of course imagine changing the message to something like

"comma at end of enumerator list is not a warning " \
"with -std=c++0x or -std=gnu++0x"

but it still stands out as different in that function so I do not
know...

/MF

[-- Attachment #2: gcc-diff --]
[-- Type: text/x-patch, Size: 2772 bytes --]

Index: gcc/cp/error.c
===================================================================
--- gcc/cp/error.c	(revision 180672)
+++ gcc/cp/error.c	(working copy)
@@ -3255,6 +3255,10 @@
 		 "user-defined literals "
 		 "only available with -std=c++0x or -std=gnu++0x");
 	break;
+      case CPP0X_ENUM_TRAILING_COMMA:
+	pedwarn (input_location, OPT_pedantic,
+		 "comma at end of enumerator list");
+	break;
       default:
 	gcc_unreachable ();
       }
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 180672)
+++ 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,7 @@
       /* 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");
+	  maybe_warn_cpp0x(CPP0X_ENUM_TRAILING_COMMA);
 	  break;
 	}
     }
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 180672)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -402,7 +402,9 @@
   /* non-static data member initializers */
   CPP0X_NSDMI,
   /* user defined literals */
-  CPP0X_USER_DEFINED_LITERALS
+  CPP0X_USER_DEFINED_LITERALS,
+  /* trailing comma in enumerations */
+  CPP0X_ENUM_TRAILING_COMMA
 } cpp0x_warn_str;
   
 /* The various kinds of operation used by composite_pointer_type. */
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, };

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PING: [C++-11 PATCH] Trailing comma in enum
  2011-10-30 14:35 ` Magnus Fromreide
@ 2011-10-30 16:37   ` Ville Voutilainen
  0 siblings, 0 replies; 4+ messages in thread
From: Ville Voutilainen @ 2011-10-30 16:37 UTC (permalink / raw)
  To: Magnus Fromreide; +Cc: gcc-patches, Jason Merrill

On 30 October 2011 12:17, Magnus Fromreide <magfr@lysator.liu.se> wrote:
> Attached is a variation where maybe_warn_cpp0x is used.
> Please note how my new pedwarn breaks the pattern in maybe_warn_cpp0x.

Looks reasonable to me, but I'm not a maintainer. :) Jason?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* PING: [C++-11 PATCH] Trailing comma in enum
       [not found] <1318776579.2081.0.camel@sara>
@ 2011-10-29  8:09 ` Magnus Fromreide
  0 siblings, 0 replies; 4+ messages in thread
From: Magnus Fromreide @ 2011-10-29  8:09 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 660 bytes --]

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.


[-- Attachment #2: gcc-diff --]
[-- Type: text/x-patch, Size: 1919 bytes --]

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, };

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-30 15:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-29 19:07 PING: [C++-11 PATCH] Trailing comma in enum Ville Voutilainen
2011-10-30 14:35 ` Magnus Fromreide
2011-10-30 16:37   ` Ville Voutilainen
     [not found] <1318776579.2081.0.camel@sara>
2011-10-29  8:09 ` Magnus Fromreide

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).