cp_parser_parameter_declaration is clever enough to tell that when we see
Type1 id(Type2
if the next token doesn't indicate a cast, we're dealing with a function
declarator. But it was only checking for '('; now it needs to check for
'{' as well.
After making that fix, I needed to change cp_parser_direct_declarator to
not assume that we successfully parsed a parameter list until we see the
closing ')'.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 365eff32e0004b7e3ac0794a2fbb5d6585f4b4d7
Author: Jason Merrill <ja...@redhat.com>
Date: Wed May 25 11:44:48 2011 -0400
PR c++/47184
* parser.c (cp_parser_parameter_declaration): Recognize
list-initialization.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index db2cb96..004ff05 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -14901,6 +14901,9 @@ cp_parser_direct_declarator (cp_parser* parser,
parser->num_template_parameter_lists
= saved_num_template_parameter_lists;
+ /* Consume the `)'. */
+ cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+
/* If all went well, parse the cv-qualifier-seq and the
exception-specification. */
if (member_p || cp_parser_parse_definitely (parser))
@@ -14915,8 +14918,6 @@ cp_parser_direct_declarator (cp_parser* parser,
if (ctor_dtor_or_conv_p)
*ctor_dtor_or_conv_p = *ctor_dtor_or_conv_p < 0;
first = false;
- /* Consume the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
/* Parse the cv-qualifier-seq. */
cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
@@ -16053,6 +16054,7 @@ cp_parser_parameter_declaration (cp_parser *parser,
of some object of type "char" to "int". */
&& !parser->in_type_id_in_expr_p
&& cp_parser_uncommitted_to_tentative_parse_p (parser)
+ && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE)
&& cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
cp_parser_commit_to_tentative_parse (parser);
/* Parse the declarator. */
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist51.C b/gcc/testsuite/g++.dg/cpp0x/initlist51.C
new file mode 100644
index 0000000..9163dd3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist51.C
@@ -0,0 +1,15 @@
+// PR c++/47184
+// { dg-options -std=c++0x }
+
+struct S
+{
+ int a;
+};
+struct T
+{
+ T(S s) {}
+};
+int main()
+{
+ T t(S{1});
+}