From patchwork Thu May 26 13:20:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 97574 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 4799AB6F8A for ; Thu, 26 May 2011 23:20:58 +1000 (EST) Received: (qmail 12389 invoked by alias); 26 May 2011 13:20:53 -0000 Received: (qmail 12244 invoked by uid 22791); 26 May 2011 13:20:52 -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; Thu, 26 May 2011 13:20:35 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4QDKYPZ001383 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 May 2011 09:20:35 -0400 Received: from [127.0.0.1] (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4QDKYqS026486 for ; Thu, 26 May 2011 09:20:34 -0400 Message-ID: <4DDE53A2.1090407@redhat.com> Date: Thu, 26 May 2011 09:20:34 -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++/48424 (function parameter packs not at the end of the list) 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 The initial specification of variadic templates required function parameter packs to be at the end of the parameter list, but that restriction was soon found to be undesirable; this patch updates G++ to support packs earlier in the parameter list as specified in the FDIS. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4903fd6cbf099822f15e6af2708ab5d54e7eae18 Author: Jason Merrill Date: Wed May 25 23:15:19 2011 -0400 PR c++/48424 * decl.c (grokparms): Function parameter packs don't need to go at the end. * pt.c (type_unification_real): But they aren't deduced otherwise. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8ab0c8a..a956dbb 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10551,12 +10551,6 @@ grokparms (tree parmlist, tree *parms) init = check_default_argument (decl, init); } - if (TREE_CODE (decl) == PARM_DECL - && FUNCTION_PARAMETER_PACK_P (decl) - && TREE_CHAIN (parm) - && TREE_CHAIN (parm) != void_list_node) - error ("parameter packs must be at the end of the parameter list"); - DECL_CHAIN (decl) = decls; decls = decl; result = tree_cons (init, type, result); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c9c25cd..ab48c8f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14262,11 +14262,24 @@ type_unification_real (tree tparms, while (parms && parms != void_list_node && ia < nargs) { - if (TREE_CODE (TREE_VALUE (parms)) == TYPE_PACK_EXPANSION) - break; - parm = TREE_VALUE (parms); + + if (TREE_CODE (parm) == TYPE_PACK_EXPANSION + && (!TREE_CHAIN (parms) || TREE_CHAIN (parms) == void_list_node)) + /* For a function parameter pack that occurs at the end of the + parameter-declaration-list, the type A of each remaining + argument of the call is compared with the type P of the + declarator-id of the function parameter pack. */ + break; + parms = TREE_CHAIN (parms); + + if (TREE_CODE (parm) == TYPE_PACK_EXPANSION) + /* For a function parameter pack that does not occur at the + end of the parameter-declaration-list, the type of the + parameter pack is a non-deduced context. */ + continue; + arg = args[ia]; ++ia; arg_expr = NULL; diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic111.C b/gcc/testsuite/g++.dg/cpp0x/variadic111.C new file mode 100644 index 0000000..378162e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic111.C @@ -0,0 +1,19 @@ +// PR c++/48424 +// { dg-options -std=c++0x } + +template +struct S +{ + template + void f(Args1... args1, Args2&&... args2) + { + } +}; + +int main() +{ + S s; + s.f(1,2.0,false,'a'); +} + +// { dg-final { scan-assembler "_ZN1SIIidEE1fIIbcEEEvidDpOT_" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic41.C b/gcc/testsuite/g++.dg/cpp0x/variadic41.C index d209766..9cfd847 100644 --- a/gcc/testsuite/g++.dg/cpp0x/variadic41.C +++ b/gcc/testsuite/g++.dg/cpp0x/variadic41.C @@ -1,3 +1,14 @@ +// A function parameter pack is only deduced if it's at the end // { dg-options "-std=gnu++0x" } template -void f(const Args&... args, int oops); // { dg-error "end" } +void f(const Args&... args, int oops); + +int main() +{ + f<>(1); + f(1); + f(1,2); + f(1,2); // { dg-error "no match" } +} + +// { dg-prune-output "note" }