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.129.124]) by sourceware.org (Postfix) with ESMTPS id 9CDB7385B53C for ; Fri, 21 Jul 2023 20:33:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CDB7385B53C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689971582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jx10y8QPJ3Lhekf5cUAQPHQKtnw+TQmAbbFw01zyKi4=; b=VHW6WDdttRXuFER1dMS98uNe8Bjj49cIcBNL6Xy46SAD/u0WFqwzr1Pm5G4iTKI5S9iQ/I yLwWtOqSGjAUU4cwjpvE/WbLrWrqHJqD3qhpuFf1fwTdcFiHmIMEgBhKFK12yftxAFpb1B 1s3DjgQuvWZDpX3mnj1A4ieAwxn5zx0= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-XN2uS5wmN82vaHVtJeIvwg-1; Fri, 21 Jul 2023 16:33:00 -0400 X-MC-Unique: XN2uS5wmN82vaHVtJeIvwg-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4054bb356a6so9129101cf.1 for ; Fri, 21 Jul 2023 13:33:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689971580; x=1690576380; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jx10y8QPJ3Lhekf5cUAQPHQKtnw+TQmAbbFw01zyKi4=; b=DKqYeHpUQBKwDQAYWsEGKP4YA85v6Q18SmIbhIYMCbS7OXjyGXH2010C6uGTSMpKTa EytOJ7zFd0+ihbv6pUxTHe2liDpUNOKtEP49JWpjfjvf+F7doYh/EgxDkswuieKuiR6o mwwGPqXH1B/GEAyRvBKn5W3vLF5Ln8yLqzJkhB+QoFnIdkQpCuD7qaubMwFF5Wd37PC2 Y0dXTBhB/BTu4P+xtIdK4Uz2WNpYjI90uKSj7dWODo7UwuUpjcO6uJx9waAbp8lf1xON 0t2xP71cSqP1mn8C+Ghu4ADTDk9SPc4gxY6GtymxWyq+5xZ9Eqw24yw8rPTaoZLKSgPO ICMw== X-Gm-Message-State: ABy/qLY4+e0fQmSvFzVBaQt7uihh+h0KaSbxYz8ZOgn6Q3OELt/enCOn xpnbQTIEjA2NqCkMgWcPY3yQc5opXISYKGmKrzgd5DY8OCWSvFnZlJS9BbJiXlgrk/3K/sKpiO0 QXLSlSXUtyoLMAx3n1tqWM/HDeg== X-Received: by 2002:a05:622a:4cc:b0:403:b23f:9e16 with SMTP id q12-20020a05622a04cc00b00403b23f9e16mr1465068qtx.2.1689971580057; Fri, 21 Jul 2023 13:33:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlElLfSXyupKxlCOfIyMfPSKAQy0S5NNB0bqJyqbnsEuZZVwA1TCYFnDXwIJvhX2YY7zVN5dBA== X-Received: by 2002:a05:622a:4cc:b0:403:b23f:9e16 with SMTP id q12-20020a05622a04cc00b00403b23f9e16mr1465052qtx.2.1689971579756; Fri, 21 Jul 2023 13:32:59 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id ff20-20020a05622a4d9400b00403f1a7be90sm1492972qtb.88.2023.07.21.13.32.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jul 2023 13:32:59 -0700 (PDT) Message-ID: <024b1945-c908-fecd-574d-597a6da976a6@redhat.com> Date: Fri, 21 Jul 2023 16:32:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 2/1] c++: passing partially inst ttp as ttp [PR110566] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <0001-c-passing-partially-inst-ttp-as-ttp-PR110566.patch> <20230721183420.1806906-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230721183420.1806906-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 7/21/23 14:34, Patrick Palka wrote: > (This is a follow-up of > https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624951.html) > > Bootstrapped and regtested on x86_64-pc-linux-gnu, how does this look? > > -- >8 -- > > The previous fix doesn't work for partially instantiated ttps primarily > because most_general_template doesn't work for them. This patch fixes > this by giving such ttps a DECL_TEMPLATE_INFO (extending the > r11-734-g2fb595f8348e16 fix) with which we can obtain the original ttp. > > This patch additionally makes us be more careful about using the correct > amount of levels from the scope of a ttp argument during > coerce_template_template_parms. > > PR c++/110566 > > gcc/cp/ChangeLog: > > * pt.cc (reduce_template_parm_level): Set DECL_TEMPLATE_INFO > on the DECL_TEMPLATE_RESULT of a reduced template template > parameter. > (add_defaults_to_ttp): Also update DECL_TEMPLATE_INFO of the > ttp's DECL_TEMPLATE_RESULT. > (coerce_template_template_parms): Make sure 'scope_args' has > the right amount of levels for the ttp argument. > (most_general_template): Handle template template parameters. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/ttp39.C: New test. > --- > gcc/cp/pt.cc | 46 ++++++++++++++++++++++++--- > gcc/testsuite/g++.dg/template/ttp39.C | 16 ++++++++++ > 2 files changed, 57 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/ttp39.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index e0ed4bc8bbb..be7119dd9a0 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -4570,8 +4570,14 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args, > TYPE_DECL, DECL_NAME (decl), type); > DECL_TEMPLATE_RESULT (decl) = inner; > DECL_ARTIFICIAL (inner) = true; > - DECL_TEMPLATE_PARMS (decl) = tsubst_template_parms > - (DECL_TEMPLATE_PARMS (orig_decl), args, complain); > + tree parms = tsubst_template_parms (DECL_TEMPLATE_PARMS (orig_decl), > + args, complain); > + DECL_TEMPLATE_PARMS (decl) = parms; > + retrofit_lang_decl (inner); > + tree orig_inner = DECL_TEMPLATE_RESULT (orig_decl); > + DECL_TEMPLATE_INFO (inner) > + = build_template_info (DECL_TI_TEMPLATE (orig_inner), > + template_parms_to_args (parms)); Should we assert that orig_inner doesn't have its own DECL_TEMPLATE_INFO? I'm wondering if it's possible to reduce the level of a TTP more than once. > } > > /* Attach the TPI to the decl. */ > @@ -7936,6 +7942,19 @@ add_defaults_to_ttp (tree otmpl) > } > } > > + tree oresult = DECL_TEMPLATE_RESULT (otmpl); > + tree gen_otmpl = DECL_TI_TEMPLATE (oresult); Hmm, here we're assuming that all TTPs have DECL_TEMPLATE_INFO? > + tree gen_ntmpl; > + if (gen_otmpl == otmpl) > + gen_ntmpl = ntmpl; > + else > + gen_ntmpl = add_defaults_to_ttp (gen_otmpl); > + > + tree nresult = copy_node (oresult); > + DECL_TEMPLATE_INFO (nresult) = copy_node (DECL_TEMPLATE_INFO (oresult)); > + DECL_TI_TEMPLATE (nresult) = gen_ntmpl; > + DECL_TEMPLATE_RESULT (ntmpl) = nresult; > + > hash_map_safe_put (defaulted_ttp_cache, otmpl, ntmpl); > return ntmpl; > } > @@ -8121,15 +8140,29 @@ coerce_template_template_parms (tree parm_tmpl, > OUTER_ARGS are not the right outer levels in this case, as they are > the args we're building up for PARM, and for the coercion we want the > args for ARG. If DECL_CONTEXT isn't set for a template template > - parameter, we can assume that it's in the current scope. In that case > - we might end up adding more levels than needed, but that shouldn't be > - a problem; any args we need to refer to are at the right level. */ > + parameter, we can assume that it's in the current scope. */ > tree ctx = DECL_CONTEXT (arg_tmpl); > if (!ctx && DECL_TEMPLATE_TEMPLATE_PARM_P (arg_tmpl)) > ctx = current_scope (); > tree scope_args = NULL_TREE; > if (tree tinfo = get_template_info (ctx)) > scope_args = TI_ARGS (tinfo); > + if (DECL_TEMPLATE_TEMPLATE_PARM_P (arg_tmpl)) > + { > + int level = TEMPLATE_TYPE_LEVEL (TREE_TYPE (gen_arg_tmpl)); > + int scope_depth = TMPL_ARGS_DEPTH (scope_args); > + if (scope_depth >= level) > + /* Only use as many levels from the scope as needed (not > + including the level of ARG). */ > + scope_args = strip_innermost_template_args > + (scope_args, scope_depth - (level - 1)); > + > + /* Add the arguments that appear at the level of ARG. */ > + tree adj_args = DECL_TI_ARGS (DECL_TEMPLATE_RESULT (arg_tmpl)); > + adj_args = TMPL_ARGS_LEVEL (adj_args, TMPL_ARGS_DEPTH (adj_args) - 1); > + scope_args = add_to_template_args (scope_args, adj_args); Maybe we should add an integer parameter to add_to_template_args so we can specify adding a certain number of levels without making a temporary copy along the way? > + } > + > pargs = add_to_template_args (scope_args, pargs); > > pargs = coerce_template_parms (gen_arg_parms, pargs, NULL_TREE, tf_none); > @@ -25985,6 +26018,9 @@ most_general_template (tree decl) > return NULL_TREE; > } > > + if (DECL_TEMPLATE_TEMPLATE_PARM_P (decl)) > + return DECL_TI_TEMPLATE (DECL_TEMPLATE_RESULT (decl)); > + > /* Look for more and more general templates. */ > while (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) > { > diff --git a/gcc/testsuite/g++.dg/template/ttp39.C b/gcc/testsuite/g++.dg/template/ttp39.C > new file mode 100644 > index 00000000000..03d7c505c4a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/ttp39.C > @@ -0,0 +1,16 @@ > +// PR c++/110566 > +// { dg-do compile { target c++20 } } > + > +template class> > +struct A; > + > +template > +struct B { > + template > + struct C { > + template class TT> > + using type = A; > + }; > +}; > + > +template struct B::C;