From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C0B7F396EC61 for ; Thu, 1 Jul 2021 15:17:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C0B7F396EC61 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-gCS_WpThOL6JZeTkYkxeyw-1; Thu, 01 Jul 2021 11:17:41 -0400 X-MC-Unique: gCS_WpThOL6JZeTkYkxeyw-1 Received: by mail-qk1-f199.google.com with SMTP id c17-20020a37e1110000b02903b3a029f1f2so4476559qkm.12 for ; Thu, 01 Jul 2021 08:17:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ruVryTWosht+XUi65kLPVSEB9lvP48X8B2XKc04mpNo=; b=fMAkwJQ3M7pGPsasyUTEGKv+pbiD2LtiBicGbZX53domE1ngYfZ8dw24eNJyHYhT3E nYzMNiz+NUxqx4vsLftOyW0l6wwkXnaJRT/G5PMwMzBe66p3+d7LjqeNJ6H+hX94ld3f Pq8rj+RsZbYtj4Aqk5TaMKV+pZnHWc+DixJn1EIS48eRxUdHYg/8ANgKm57Hjf+U8GCL hdYfmSz1s5mIJJ1BpsxFS8OkZWmO/6vd33oeLfQfPSnzlorO/iapja+WhFIpCklQGs5L xIrcdMts8debSB+QtQb7RWjFBDWBWm6cPoVRktOP4GS1AFvJqSGuQuwQ86a1zIT9dNul tW2A== X-Gm-Message-State: AOAM533lOuuXTJmXAI5juqFY17eB652NHr/4JNRfVWqdpHej6wqhi+8R WHMrC7des2DCSBY+WZ3J+R2gSquqDYnJiERVF0wCMI8gULJUCnhrsJrUxnNfWLZLqcEAj2K5Zk4 zpB3iF9XHcAx7cTgIbDT/AGuWGAMCgpxQbzUX5rmA05SJmvIykWRqMVekrO1+aWMQVg== X-Received: by 2002:a37:391:: with SMTP id 139mr104406qkd.28.1625152659460; Thu, 01 Jul 2021 08:17:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwas8WIWtMoiM6VQAx38lgesrUqXmwq1MuLiRPGQ8/WRjT0y6llVQnCcWwzNqSPInu1Z/q7WQ== X-Received: by 2002:a37:391:: with SMTP id 139mr104394qkd.28.1625152659158; Thu, 01 Jul 2021 08:17:39 -0700 (PDT) Received: from [192.168.1.148] (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id r4sm99116qtn.57.2021.07.01.08.17.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Jul 2021 08:17:38 -0700 (PDT) Subject: Re: [PATCH] c++: unqualified member template in constraint [PR101247] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20210630212715.2912419-1-ppalka@redhat.com> From: Jason Merrill Message-ID: <4bbab715-f77d-52aa-d5f8-198fd09bf98a@redhat.com> Date: Thu, 1 Jul 2021 11:17:37 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210630212715.2912419-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thu, 01 Jul 2021 15:17:44 -0000 On 6/30/21 5:27 PM, Patrick Palka wrote: > Here any_template_parm_r is failing to mark the template parameters > that're implicitly used by the unqualified use of 'd' inside the constraint, > because the code to do so assumes each level of a template parameter > list points to the corresponding primary template, but here the > parameter level for A in the out-of-line definition of A::B does not > (nor do the parameter levels for A and C in the definition of A::C), > which causes us to overlook the sharing. > > So it seems we can't in general depend on the TREE_TYPE of a template > parameter level being non-empty here. This patch partially fixes this > by rewriting the relevant part of any_template_parm_r to not depend on > the TREE_TYPE of outer levels. We still depend on the innermost level > to point to the innermost primary template, so unfortunately we still > crash on the commented out lines in the below testcase. (The problem > there ultimately seems to be in push_template_decl, where we consider > the out-of-line definition of A::C to not be primary since > template_parm_scope_p is false, so DECL_PRIMARY_TEMPLATE never gets set. > Fixing that might not be safe enough to backport, but hopefully this > partial fix is.) > > Bootstrapped and regtested on x86_64-pc-linux-gnu, also tested on > range-v3 and cmcstl2, does this look OK for trunk/11? OK. Are you looking at fixing the commented-out line in a separate patch? > PR c++/101247 > > gcc/cp/ChangeLog: > > * pt.c (any_template_parm_r) : Rewrite to > use common_enclosing_class and to not depend on the TREE_TYPE > of outer levels pointing to the corresponding primary template. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-memtmpl4.C: New test. > --- > gcc/cp/pt.c | 23 ++++----------- > .../g++.dg/cpp2a/concepts-memtmpl4.C | 28 +++++++++++++++++++ > 2 files changed, 33 insertions(+), 18 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-memtmpl4.C > > diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c > index db769d59951..a8fdd2e177e 100644 > --- a/gcc/cp/pt.c > +++ b/gcc/cp/pt.c > @@ -10735,24 +10735,11 @@ any_template_parm_r (tree t, void *data) > { > /* If T is a member template that shares template parameters with > ctx_parms, we need to mark all those parameters for mapping. */ > - tree dparms = DECL_TEMPLATE_PARMS (t); > - tree cparms = ftpi->ctx_parms; > - while (TMPL_PARMS_DEPTH (dparms) > ftpi->max_depth) > - dparms = TREE_CHAIN (dparms); > - while (TMPL_PARMS_DEPTH (cparms) > TMPL_PARMS_DEPTH (dparms)) > - cparms = TREE_CHAIN (cparms); > - while (dparms > - && (TREE_TYPE (TREE_VALUE (dparms)) > - != TREE_TYPE (TREE_VALUE (cparms)))) > - dparms = TREE_CHAIN (dparms), > - cparms = TREE_CHAIN (cparms); > - if (dparms) > - { > - int ddepth = TMPL_PARMS_DEPTH (dparms); > - tree dargs = TI_ARGS (get_template_info (DECL_TEMPLATE_RESULT (t))); > - for (int i = 0; i < ddepth; ++i) > - WALK_SUBTREE (TMPL_ARGS_LEVEL (dargs, i+1)); > - } > + if (tree dtmpl = TREE_TYPE (INNERMOST_TEMPLATE_PARMS (ftpi->ctx_parms))) > + if (tree com = common_enclosing_class (DECL_CONTEXT (t), > + DECL_CONTEXT (dtmpl))) > + if (tree ti = CLASSTYPE_TEMPLATE_INFO (com)) > + WALK_SUBTREE (TI_ARGS (ti)); > } > break; > > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-memtmpl4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-memtmpl4.C > new file mode 100644 > index 00000000000..625149e5025 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-memtmpl4.C > @@ -0,0 +1,28 @@ > +// PR c++/101247 > +// { dg-do compile { target concepts } } > +// A variant of concepts-memtmpl3.C where f is defined outside A's definition. > + > +template struct A { > + template static constexpr bool d = true; > + struct B; > + template struct C; > +}; > + > +template > +struct A::B { > + template static void f(c) requires d; > +}; > + > +template > +template > +struct A::C { > + template static void f(c) requires d; > + static void g() requires d; > +}; > + > +int main() > +{ > + A::B::f(0); > + A::C::f(0); > + // A::C::g(); > +} >