From patchwork Wed May 15 14:33:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 244091 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 4774A2C0099 for ; Thu, 16 May 2013 00:33:25 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=tAk4ZbEgyL7QB/keuo2mn1hzZizlRXYw+rAGPzjxWAETGeEov7 vLaW3hUb/dMD8KG3+8HFABj7XG3t322taf+Sl6U9gC3be1d9OlZU3bBdaPE/FaLv 4nMP2syBSf9dkh/Mdbz2TxF7X963wawvNlw+h8pDQf7u2HKuCVHuJPaUM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=pGQlvALyxptQXKYaDKusxUb4gCo=; b=fk9cOF0OzkK0waptHIGl NAIq8c3tKmfRus5d5T6Uw3C9jVEoM1unnwJ1q1bh0GLSFZf28MJ83ktL6nvctSsA EuL3zpz+7Zk7qne9DrIzpRhRsduQzYpHAHcaWBkzNXXeKbFta3CSHPNwkbSmTKgs TXN5lv8WVrwPU1bUVrikK9Y= Received: (qmail 15122 invoked by alias); 15 May 2013 14:33:18 -0000 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 Received: (qmail 15112 invoked by uid 89); 15 May 2013 14:33:17 -0000 X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 15 May 2013 14:33:14 +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 r4FEXCw2028994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 May 2013 10:33:13 -0400 Received: from localhost (dhcp-193-230.cdg.redhat.com [10.32.193.230]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r4FEXBwx005070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 May 2013 10:33:12 -0400 Received: by localhost (Postfix, from userid 1000) id B790C2C0049; Wed, 15 May 2013 16:33:10 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Jason Merrill Subject: PR c++/56782 - Regression with empty pack expansions X-URL: http://www.redhat.com Date: Wed, 15 May 2013 16:33:10 +0200 Message-ID: <877gj0pb2x.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Hello, In the example of the patch below, during the instantiation of is_convertible at #1, we see at some point Tuple<>. (Let's note '{}' an empty argument pack.) In that context, during the partial specialization the member template template Tuple<>::Tuple... >::value, int >::type > Let's look at what happens to the expansion "is_convertible...." To express the result of that expansion tsubst_pack_expansion receives the expansion is_convertible, with the argument list [{}]. This function should detect that we have an empty argument pack for the parameter pack T and no argument pack for the parameter pack U. It should thus return a pack expansion "is_convertible..." that has this information: "I have gotten an argument list, that is not complete because U doesn't have any argument pack; the argument pack for T is '{}', so I'll wait for the next time I am passed to tsubst_pack_expansion with enough additional argument packs, to really perform the substitution". That information is conveyed by attaching the the '{}' to the PACK_EXPANSION_EXTRA property of the pack expansion returned by tsubst_pack_expansion. The problem in this report is that we are not setting PACK_EXPANSION_EXTRA when the non-complete argument pack list is made of an empty argument pack, because use_pack_expansion_extra_args_p doesn't detect this case. Fixed thus. gcc/cp/ * pt.c (use_pack_expansion_extra_args_p): When at least a parameter pack has an empty argument pack, and another parameter pack has no argument pack at all, use the PACK_EXPANSION_EXTRA mechanism. Update comments. --- gcc/cp/pt.c | 58 +++++++++++++++++++++-------- gcc/testsuite/g++.dg/cpp0x/variadic143.C | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic143.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7430289..d31af55 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9158,31 +9158,57 @@ use_pack_expansion_extra_args_p (tree parm_packs, if (parm_packs == NULL_TREE) return false; + /* The general reasoning is the following: + + If one pack has an expansion and another pack has a normal + argument or if one pack has an empty argument and another one + hasn't then tsubst_pack_expansion cannot perform the substitution + and need to fall back on the PACK_EXPANSION_EXTRA mechanism so we + must return TRUE. */ + bool has_expansion_arg = false; - for (int i = 0 ; i < arg_pack_len; ++i) - { - bool has_non_expansion_arg = false; + if (arg_pack_len == 0) + { + /* So let's rule out the particular case of a zero argument pack + length. It means either there is parameter pack that has an + empty argument argument pack, or there are no argument packs + at all. In the former case, if there is also at least a + parameter pack that has no argument pack, then we must return + true.*/ for (tree parm_pack = parm_packs; parm_pack; parm_pack = TREE_CHAIN (parm_pack)) { tree arg = TREE_VALUE (parm_pack); - if (argument_pack_element_is_expansion_p (arg, i)) - has_expansion_arg = true; - else - has_non_expansion_arg = true; + if (arg + && ARGUMENT_PACK_P (arg) + && TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) == 0 + && has_empty_arg) + return true; } - - /* If one pack has an expansion and another pack has a normal - argument or if one pack has an empty argument another one - hasn't then tsubst_pack_expansion cannot perform the - substitution and need to fall back on the - PACK_EXPANSION_EXTRA mechanism. */ - if ((has_expansion_arg && has_non_expansion_arg) - || (has_empty_arg && (has_expansion_arg || has_non_expansion_arg))) - return true; } + else + /* So let's handle the general case. */ + for (int i = 0 ; i < arg_pack_len; ++i) + { + bool has_non_expansion_arg = false; + for (tree parm_pack = parm_packs; + parm_pack; + parm_pack = TREE_CHAIN (parm_pack)) + { + tree arg = TREE_VALUE (parm_pack); + + if (argument_pack_element_is_expansion_p (arg, i)) + has_expansion_arg = true; + else + has_non_expansion_arg = true; + } + + if ((has_expansion_arg && has_non_expansion_arg) + || (has_empty_arg && (has_expansion_arg || has_non_expansion_arg))) + return true; + } return false; } diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic143.C b/gcc/testsuite/g++.dg/cpp0x/variadic143.C new file mode 100644 index 0000000..7737b4c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic143.C @@ -0,0 +1,63 @@ +// PR c++/56782 +// { dg-options -std=c++0x } + +template +T&& declval(); + +struct is_convertible_impl { + template + static void sink(T); + + template(declval()))> + static auto test(int) -> char; + + template + static auto test(...) -> char(&)[2]; +}; + +template +struct is_convertible : is_convertible_impl +{ + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct enable_if {}; + +template +struct enable_if { typedef T type; }; + +template +struct conditional { typedef If type; }; + +template +struct conditional { typedef Else type; }; + +template +struct and_; + +template<> +struct and_<> +{ + static const bool value = true; +}; + +template +struct and_

: P +{ +}; + +template +struct and_ : conditional::type +{ +}; + +template +struct Tuple { + template... >::value, int>::type + > + Tuple(U&&...){} +}; + +static_assert(is_convertible, Tuple<>>::value, "Ouch"); //#1