From: Jason Merrill Date: Fri, 14 Oct 2011 19:12:57 +0000 (-0400) Subject: re PR c++/50563 ([C++0x] Weird syntax acceptance rules for non-static data members... X-Git-Tag: releases/gcc-4.7.0~3094 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7204877f43b9e70fbb357d26c43c3d26c5fbbc41;p=thirdparty%2Fgcc.git re PR c++/50563 ([C++0x] Weird syntax acceptance rules for non-static data members initialized in place) PR c++/50563 * parser.c (cp_parser_cache_group): Handle end==CPP_COMMA. (cp_parser_save_nsdmi): Pass it. From-SVN: r180003 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b55e2947bc43..db16902f959c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-10-14 Jason Merrill + 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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cabe9aac4bd3..ea0c4dc2ab6c 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/ChangeLog b/gcc/testsuite/ChangeLog index 80ef91c87f97..ed5d30e7fece 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-10-14 Jason Merrill + 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 index 000000000000..526f29ae2850 --- /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; +};