From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 65E3A385B80B for ; Fri, 3 Apr 2020 17:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E3A385B80B Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-5Qg8Ae6jNwy9Sn_dd5qMhA-1; Fri, 03 Apr 2020 13:49:39 -0400 X-MC-Unique: 5Qg8Ae6jNwy9Sn_dd5qMhA-1 Received: by mail-qv1-f71.google.com with SMTP id dh19so6389371qvb.23 for ; Fri, 03 Apr 2020 10:49:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=MzVe9h2OFbFDlFFFG+vJVOfR/kZJ4FoRdiA9iQjydck=; b=j037KALGjHcG/UoPBbpOwghn3+ZM1I7Mb7nieGHNSpVLG2qvy6mbIIeGng3tNizjdL S2ULVXlXvocqE3/8PJMcg/qXAdqyAsQPPJGU/dXG4iCnO8WDVRIeS/0vYV7Y/UIrk7OM FIPpskXHlmGg9t53Rl7qeEgjQ9PUVpaiBoy35lliIsCKY9JVrDH/5bEbAg25tzDbrNZu zS+I4s8RoCGg3xFWjGaMpPNm+IG42WZb0JgBYz8ZbO3DBFwe5G97d13tKCecIQh9c40B AiQXFgXaaXDjDNji9U74ku295bvHI217dQAKyFfZgQJinZTzK9b+wKBN4yXTYtePUgPl eMVw== X-Gm-Message-State: AGi0PuaIpJCxQzvkOuKyYfMkQSZXVh+FhhqaaF/21W709tguYZTw1gUP n5P4QRdRFUkciV1B/fD/Wg+/AseEE7IFd3A4pUxJgRmC1o34cRC1IVuTKRLakxrRe+sGh2vkuRl v5i4iSyapdefV1mg5AA== X-Received: by 2002:a37:648:: with SMTP id 69mr10450152qkg.353.1585936178413; Fri, 03 Apr 2020 10:49:38 -0700 (PDT) X-Google-Smtp-Source: APiQypL5btqSuqoNS0Gz+Sh75LyyDnoPGDKxZqfcQjRVakdvJMmmQ+uehk6I6HDMpGUAMkxol3gRKw== X-Received: by 2002:a37:648:: with SMTP id 69mr10450115qkg.353.1585936177947; Fri, 03 Apr 2020 10:49:37 -0700 (PDT) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id y16sm269242qtj.32.2020.04.03.10.49.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 10:49:37 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: alias template and parameter packs (PR91966). Date: Fri, 3 Apr 2020 13:49:35 -0400 Message-Id: <20200403174935.30466-1-jason@redhat.com> X-Mailer: git-send-email 2.18.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-30.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2020 17:49:42 -0000 In this testcase, when we do a pack expansion of count_better_mins, nums appears both in the definition of count_better_mins and as its templat= e argument. The intent is that we get a expansion over pairs of elements of the pack, i.e. less<2,2>, less<2,7>, less<7,2>, .... But if we substitute into the definition of count_better_mins when parsing the template, we end up with sum...>, which never gives us less<2,7>. We could deal with this by somehow marking up the use of 'nums' as an argument for 'num', but it's simpler to mark the alias as complex, so we need to instantiate it later with all its arguments rather than replace it early with its expansion. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-04-03 Jason Merrill =09PR c++/91966 =09* pt.c (complex_pack_expansion_r): New. =09(complex_alias_template_p): Use it. --- gcc/cp/pt.c | 31 +++++- gcc/testsuite/g++.dg/cpp0x/variadic-alias2.C | 103 +++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic-alias2.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bd30c96a12a..b602f9f82c7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6351,6 +6351,33 @@ uses_all_template_parms_r (tree t, void *data_) return 0; } =20 +/* for_each_template_parm any_fn callback for complex_alias_template_p. *= / + +static int +complex_pack_expansion_r (tree t, void *data_) +{ + /* An alias template with a pack expansion that expands a pack from the + enclosing class needs to be considered complex, to avoid confusion wi= th + the same pack being used as an argument to the alias's own template + parameter (91966). */ + if (!PACK_EXPANSION_P (t)) + return 0; + struct uses_all_template_parms_data &data + =3D *(struct uses_all_template_parms_data*)data_; + for (tree pack =3D PACK_EXPANSION_PARAMETER_PACKS (t); pack; + pack =3D TREE_CHAIN (pack)) + { + tree parm_pack =3D TREE_VALUE (pack); + if (!TEMPLATE_PARM_P (parm_pack)) +=09continue; + int idx, level; + template_parm_level_and_index (parm_pack, &level, &idx); + if (level < data.level) +=09return 1; + } + return 0; +} + static bool complex_alias_template_p (const_tree tmpl) { @@ -6371,7 +6398,9 @@ complex_alias_template_p (const_tree tmpl) for (int i =3D 0; i < len; ++i) data.seen[i] =3D false; =20 - for_each_template_parm (pat, uses_all_template_parms_r, &data, NULL, tru= e); + if (for_each_template_parm (pat, uses_all_template_parms_r, &data, +=09=09=09 NULL, true, complex_pack_expansion_r)) + return true; for (int i =3D 0; i < len; ++i) if (!data.seen[i]) return true; diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-alias2.C b/gcc/testsuite/g= ++.dg/cpp0x/variadic-alias2.C new file mode 100644 index 00000000000..ab64866d35f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic-alias2.C @@ -0,0 +1,103 @@ +// PR c++/91966 +// { dg-do compile { target c++11 } } + +// Reduced to this include-free example. Further reduction is hard: Either +// the bug(?) disappears, or the program becomes meaningless. + +template +struct list {}; + +struct nil; + +//////////////////////////////////////////////////////////////////////////= ////// + +template +struct number { + constexpr /*implicit*/ operator int() const { return n; } + using type =3D number; +}; + +using false_ =3D number<0>; +using true_ =3D number<1>; + +static_assert(!false_{}, ""); +static_assert(true_{}, ""); + +template using numbers =3D list...>; + +//////////////////////////////////////////////////////////////////////////= ////// + +template +struct less_impl; + +template +struct less_impl, number> + : number<(lhs < rhs)> {}; + +template using less =3D typename less_impl= ::type; + +//////////////////////////////////////////////////////////////////////////= ////// + +template +struct sum_impl { + static_assert(sizeof...(vs) =3D=3D 0, "see specialization"); + using type =3D v0; +}; + +template +struct sum_impl, number, vs...> + : sum_impl, vs...> {}; + +template using sum =3D typename sum_impl::type; + +//////////////////////////////////////////////////////////////////////////= ////// + +template +struct conditional_impl { + static_assert(num{}, "see specialization"); + + template + using type =3D T; +}; + +template<> +struct conditional_impl { + template + using type =3D F; +}; + +template +using conditional =3D typename conditional_impl::template type; + +//////////////////////////////////////////////////////////////////////////= ////// + +template +struct min_filter_impl; + +template +struct min_filter_impl> { + template + using count_better_mins =3D sum...>; + + using type =3D list, nil, nums>...>; + +//using debug =3D list, nil, void>...>= ; + +// error: expansion pattern 'conditional...>::type, nil, void>' contains no parameter packs + +}; + +template using min_filter =3D typename min_filter_impl::ty= pe; + +//////////////////////////////////////////////////////////////////////////= ////// + +void test_min_filter() { + using computed =3D min_filter>; + using expected =3D list, nil, number<2>>; + (void)(computed{} =3D expected{});// compiles for identical types + +// error: no match for 'operator=3D' (operand types are 'computed' {aka 'l= ist, number<7>, number<2> >'} and 'expected' {aka 'list= , nil, number<2> >'}) + +} + +int main() {} base-commit: 2b1e849b35bfe694b09f090397944e11c9f1dc04 --=20 2.18.1