]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50563 ([C++0x] Weird syntax acceptance rules for non-static data members...
authorJason Merrill <jason@redhat.com>
Fri, 14 Oct 2011 19:12:57 +0000 (15:12 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 14 Oct 2011 19:12:57 +0000 (15:12 -0400)
PR c++/50563
* parser.c (cp_parser_cache_group): Handle end==CPP_COMMA.
(cp_parser_save_nsdmi): Pass it.

From-SVN: r180003

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C [new file with mode: 0644]

index b55e2947bc438eb1f44028ba7f2923a4e96e0c4a..db16902f959c6137e37a1fda8d3b3b715dbaa770 100644 (file)
@@ -1,5 +1,9 @@
 2011-10-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/50563
+       * parser.c (cp_parser_cache_group): Handle end==CPP_COMMA.
+       (cp_parser_save_nsdmi): Pass it.
+
        PR c++/50507
        * method.c (walk_field_subobs): Check for NSDMI before
        complaining about uninitialized fields.
index cabe9aac4bd32f045f92ab6008a070e8e80220ca..ea0c4dc2ab6c1bc9cfe9306e8230e9930d0cd194 100644 (file)
@@ -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.  */
index 80ef91c87f97935f691c95e52042366ef88cb4f6..ed5d30e7feceede7ff475f1b58ed6344d20c1ef0 100644 (file)
@@ -1,5 +1,8 @@
 2011-10-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/50563
+       * g++.dg/cpp0x/nsdmi-list1.C: New.
+
        PR c++/50507
        * g++.dg/cpp0x/nsdmi-const1.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-list1.C
new file mode 100644 (file)
index 0000000..526f29a
--- /dev/null
@@ -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;
+};