From patchwork Wed May 25 19:39:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 97405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D32D3B6F99 for ; Thu, 26 May 2011 05:40:16 +1000 (EST) Received: (qmail 12345 invoked by alias); 25 May 2011 19:40:15 -0000 Received: (qmail 12335 invoked by uid 22791); 25 May 2011 19:40:14 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 May 2011 19:40:00 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4PJdxeG021681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 May 2011 15:39:59 -0400 Received: from [127.0.0.1] (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4PJdxgT008883 for ; Wed, 25 May 2011 15:39:59 -0400 Message-ID: <4DDD5B0E.3050500@redhat.com> Date: Wed, 25 May 2011 15:39:58 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/47184 (list-initialized temporary in parenthesized initializer) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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}); +}