public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] Trailing comma in enum
@ 2011-10-09 15:10 Magnus Fromreide
  2011-11-04 17:41 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Magnus Fromreide @ 2011-10-09 15:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi.

As I understand it C++11 allows trailing commas in enum definitions.
Thus I think the following little patch should be included.

On a side note I have to say that the effects of pedwarn_cxx98 are
unexpected, especially in light of the comment above the function body.

/MF

[-- Attachment #2: Type: text/plain, Size: 406 bytes --]

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++0x 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++0x-mode.

[-- Attachment #3: patch_enum_comma --]
[-- Type: text/x-patch, Size: 2048 bytes --]

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" }
+
+enum x { y, }; // { dg-warning "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 -std=c++0x" }
+
+enum x { y, };
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 179711)
+++ gcc/cp/parser.c	(working copy)
@@ -13444,6 +13444,7 @@ cp_parser_elaborated_type_specifier (cp_parser* pa
 
    enum-specifier:
      enum-head { enumerator-list [opt] }
+     enum-head { enumerator-list , } [C++0x]
 
    enum-head:
      enum-key identifier [opt] enum-base [opt]
@@ -13463,6 +13464,8 @@ cp_parser_elaborated_type_specifier (cp_parser* pa
    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++0x]
 
    Returns an ENUM_TYPE representing the enumeration, or NULL_TREE
    if the token stream isn't an enum-specifier after all.  */
@@ -13802,8 +13805,9 @@ cp_parser_enumerator_list (cp_parser* parser, tree
       /* 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;
 	}
     }

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

* Re: [C++ Patch] Trailing comma in enum
  2011-10-09 15:10 [C++ Patch] Trailing comma in enum Magnus Fromreide
@ 2011-11-04 17:41 ` Jason Merrill
  2011-11-04 18:48   ` Ville Voutilainen
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2011-11-04 17:41 UTC (permalink / raw)
  To: Magnus Fromreide; +Cc: gcc-patches, Ville Voutilainen

Applied.  Sorry for the delay, thanks for the pings.

Jason

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

* Re: [C++ Patch] Trailing comma in enum
  2011-11-04 17:41 ` Jason Merrill
@ 2011-11-04 18:48   ` Ville Voutilainen
  2011-11-04 19:07     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Ville Voutilainen @ 2011-11-04 18:48 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Magnus Fromreide, gcc-patches

On 4 November 2011 19:38, Jason Merrill <jason@redhat.com> wrote:
> Applied.  Sorry for the delay, thanks for the pings.

So we want to pedwarn directly in parser, rather than use maybe_warn_cpp0x?
Magnus did a newer revision of the patch that uses maybe_warn_cpp0x, although
I don't know what the usual policy for that is.

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

* Re: [C++ Patch] Trailing comma in enum
  2011-11-04 18:48   ` Ville Voutilainen
@ 2011-11-04 19:07     ` Jason Merrill
  2011-11-04 19:27       ` Ville Voutilainen
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2011-11-04 19:07 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: Magnus Fromreide, gcc-patches

On 11/04/2011 02:37 PM, Ville Voutilainen wrote:
> On 4 November 2011 19:38, Jason Merrill<jason@redhat.com>  wrote:
>> Applied.  Sorry for the delay, thanks for the pings.
>
> So we want to pedwarn directly in parser, rather than use maybe_warn_cpp0x?
> Magnus did a newer revision of the patch that uses maybe_warn_cpp0x, although
> I don't know what the usual policy for that is.

Oops, I was ignoring the pings when looking for the actual patch.  :)

But in general I've been only been using maybe_warn_cpp0x for larger 
features.

Jason

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

* Re: [C++ Patch] Trailing comma in enum
  2011-11-04 19:07     ` Jason Merrill
@ 2011-11-04 19:27       ` Ville Voutilainen
  0 siblings, 0 replies; 5+ messages in thread
From: Ville Voutilainen @ 2011-11-04 19:27 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Magnus Fromreide, gcc-patches

On 4 November 2011 20:53, Jason Merrill <jason@redhat.com> wrote:
> Oops, I was ignoring the pings when looking for the actual patch.  :)
> But in general I've been only been using maybe_warn_cpp0x for larger
> features.

Understood. Modification to cp-tree.h make rebuilds heavier, so I don't feel
strongly about it.

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

end of thread, other threads:[~2011-11-04 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-09 15:10 [C++ Patch] Trailing comma in enum Magnus Fromreide
2011-11-04 17:41 ` Jason Merrill
2011-11-04 18:48   ` Ville Voutilainen
2011-11-04 19:07     ` Jason Merrill
2011-11-04 19:27       ` Ville Voutilainen

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).