From patchwork Tue Aug 30 04:27:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 112177 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 D137CB6F72 for ; Tue, 30 Aug 2011 14:28:21 +1000 (EST) Received: (qmail 21331 invoked by alias); 30 Aug 2011 04:28:14 -0000 Received: (qmail 21306 invoked by uid 22791); 30 Aug 2011 04:28:08 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Tue, 30 Aug 2011 04:27:47 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7U4Rl6x004471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 30 Aug 2011 00:27:47 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7U4RkNp022091 for ; Tue, 30 Aug 2011 00:27:47 -0400 Received: from [0.0.0.0] ([10.3.113.12]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p7U4Rjtg027173 for ; Tue, 30 Aug 2011 00:27:46 -0400 Message-ID: <4E5C66C1.6050003@redhat.com> Date: Tue, 30 Aug 2011 00:27:45 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20110817 Thunderbird/6.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50209 (DR 994, allow initializer-list default args) 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 DR 994 added default arguments to the set of places that a brace-enclosed initializer list can appear in C++11. This patch implements that. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5ba9be05f72a270674e434e447d50c4b8f6d30f8 Author: Jason Merrill Date: Mon Aug 29 00:54:22 2011 -0400 PR c++/50209 Core DR 994 * parser.c (cp_parser_default_argument): Use cp_parser_initializer_clause. (cp_parser_late_parsing_default_args): Likewise. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 84b8c60..c862a7d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16535,6 +16535,7 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p) tree default_argument = NULL_TREE; bool saved_greater_than_is_operator_p; bool saved_local_variables_forbidden_p; + bool non_constant_p; /* Make sure that PARSER->GREATER_THAN_IS_OPERATOR_P is set correctly. */ @@ -16548,7 +16549,9 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p) if (template_parm_p) push_deferring_access_checks (dk_no_deferred); default_argument - = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL); + = cp_parser_initializer_clause (parser, &non_constant_p); + if (BRACE_ENCLOSED_INITIALIZER_P (default_argument)) + maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); if (template_parm_p) pop_deferring_access_checks (); parser->greater_than_is_operator_p = saved_greater_than_is_operator_p; @@ -20731,6 +20734,7 @@ static void cp_parser_late_parsing_default_args (cp_parser *parser, tree fn) { bool saved_local_variables_forbidden_p; + bool non_constant_p; tree parm, parmdecl; /* While we're parsing the default args, we might (due to the @@ -20775,12 +20779,14 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn) start_lambda_scope (parmdecl); /* Parse the assignment-expression. */ - parsed_arg = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL); + parsed_arg = cp_parser_initializer_clause (parser, &non_constant_p); if (parsed_arg == error_mark_node) { cp_parser_pop_lexer (parser); continue; } + if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg)) + maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); if (!processing_template_decl) parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist58.C b/gcc/testsuite/g++.dg/cpp0x/initlist58.C new file mode 100644 index 0000000..dfb9f0c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist58.C @@ -0,0 +1,17 @@ +// PR c++/50209 +// { dg-options -std=c++0x } + +struct S { int i,j; }; + +struct A +{ + static void f (S = {1,2}); +}; + +void f (S = {3,4}); + +int main() +{ + A::f(); + f(); +}