public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/50563 (NSDMI and multiple declarator list)
@ 2011-10-14 18:20 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-10-14 18:20 UTC (permalink / raw)
  To: gcc-patches List

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

The problem here was that we were saving away the second declarator as 
part of the NSDMI for the first declarator.  Fixed by stopping at a 
non-nested comma.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 50563.patch --]
[-- Type: text/x-patch, Size: 1576 bytes --]

commit 09f16be794e871607c2bb46bf74206ee40af1b74
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Oct 13 17:51:13 2011 -0400

    	PR c++/50563
    	* parser.c (cp_parser_cache_group): Handle end==CPP_COMMA.
    	(cp_parser_save_nsdmi): Pass it.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index cabe9aa..ea0c4dc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20617,7 +20617,8 @@ cp_parser_save_nsdmi (cp_parser* parser)
   cp_token *last;
   tree node;
 
-  cp_parser_cache_group (parser, CPP_CLOSE_PAREN, /*depth=*/0);
+  /* Save tokens until the next comma or semicolon.  */
+  cp_parser_cache_group (parser, CPP_COMMA, /*depth=*/0);
 
   last = parser->lexer->next_token;
 
@@ -21719,6 +21720,12 @@ cp_parser_cache_group (cp_parser *parser,
 	   kind of syntax error.  */
 	return true;
 
+      /* If we're caching something finished by a comma (or semicolon),
+	 such as an NSDMI, don't consume the comma.  */
+      if (end == CPP_COMMA
+	  && (token->type == CPP_SEMICOLON || token->type == CPP_COMMA))
+	return false;
+
       /* Consume the token.  */
       cp_lexer_consume_token (parser->lexer);
       /* See if it starts a new group.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C
new file mode 100644
index 0000000..526f29a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C
@@ -0,0 +1,14 @@
+// PR c++/50563
+// { dg-options -std=c++0x }
+
+struct S1 {
+  int a{10}, b{20};     // OK
+};
+
+struct S2 {
+  int a, b = 20;        // OK
+};
+
+struct S3 {
+  int a = 10, b = 20;
+};

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-14 17:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-14 18:20 C++ PATCH for c++/50563 (NSDMI and multiple declarator list) Jason Merrill

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