From patchwork Fri Jul 21 18:34:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 124055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp394370vqg; Fri, 21 Jul 2023 11:35:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlHumw59hCItX7jRY0PVyvA5ztW0gLuuyGYoJPKkXn7wu2135XJiu+s+HcyX56sLfPpkjNRQ X-Received: by 2002:aa7:dcd7:0:b0:521:a760:d411 with SMTP id w23-20020aa7dcd7000000b00521a760d411mr2100781edu.2.1689964513948; Fri, 21 Jul 2023 11:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689964513; cv=none; d=google.com; s=arc-20160816; b=gwKFzMqO3Mf/9CSzHJ3WLyl+uNpPaAfveWBRI90SZD7LtwchGpIcMKbGUHuKqFwuEc RTHcMOeY66X1ef796AgR7Of1TKDqmgbTKvs47i5I+wy9XlhQ+kuL0NzCzqhPtDjLro25 3nX2YTlkRD5jPtg8M85T5tThlMNM3sbU5v1JIrUVuGuhrVMnAkGrZduZkGmBZYxJVVOO Ys3FhoD+B/e1axf85512COy9V79IKI+/gOF869e9Ka5QswE1UDbvtATzKQ5jcEFYBmtC tPyJAVPdxXFzztO1EXsM+CK3ei4o07oSiLPyXAjeHqZEVjLGChxDKtktED0uqOScllKY hbhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=bQMk1a4vbqqAVfqiFC+NO+EHqs8GIifmiJGWDMaYL5Y=; fh=M5GO8duY/t9+1sJXvBSRQ4u8k9z8sLFDsSO1kARbltQ=; b=U6RwREyznkJRjmlPDraCNWTDPFN/rbcRrqjPUZzWx9pMFiyHNnhxOkt5/AMigU9aTa wwJDmi9V+XT89ufsUq6vhUCQj6ciPGTJBVhVR33uQsy/m7XCzfjnKPhv/vAUS4BoGL5J reBqwXNKvt2fzdfEMke38/wUlpRSfB8DaY5dzB+V8Z+yCuSfPpVbh3I6glGGbQmXcuhF CwTiHK1A056GcObYX2zBuva32+iylHg9qs1cj+VsE5rr8GyLj1f+9HpyJQoXjLf+kNSE hhBffEYaQaWAkB3FzPj2deXNyTsIc22ZII7w9HzmSzdf5YvXaMkKjueBvWup3TfRVjgo oCYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YdS3Psmk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t18-20020aa7d4d2000000b0051d882750d2si2609860edr.569.2023.07.21.11.35.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 11:35:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YdS3Psmk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 614DB3853D27 for ; Fri, 21 Jul 2023 18:35:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 614DB3853D27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689964512; bh=bQMk1a4vbqqAVfqiFC+NO+EHqs8GIifmiJGWDMaYL5Y=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YdS3PsmkPPvEGYVRK3fPR/RSZGtT70+dHBng+ZaUhmnkmZVzovCr57atogC1IdBSL 4EZKm/MuFYgg7F0HAhgW+CuXlZl9ReNPX8msWZwota9K+K4zqn8NuoQbL8IiGiSWjR 0L6Nyh+hk1AMlD0tfbNJQnz/2rt3wb5UNyDJcl1s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 80A4D3858410 for ; Fri, 21 Jul 2023 18:34:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A4D3858410 Received: from mail-ua1-f70.google.com (mail-ua1-f70.google.com [209.85.222.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-t8R-8j_IPu-QsBUEycm9Dg-1; Fri, 21 Jul 2023 14:34:25 -0400 X-MC-Unique: t8R-8j_IPu-QsBUEycm9Dg-1 Received: by mail-ua1-f70.google.com with SMTP id a1e0cc1a2514c-79190becbd7so521887241.3 for ; Fri, 21 Jul 2023 11:34:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689964464; x=1690569264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bQMk1a4vbqqAVfqiFC+NO+EHqs8GIifmiJGWDMaYL5Y=; b=QFwiyp5f+KNbwpu31BG3g6gkPDV7fv9DnRz/1GJPMMLvqjVxJ0ana+tlsVWq/NMMX3 iyxn5xmma88uvY622ZaSkl7a+W/qecR9CsapU7IgFfoKEgFr0o8/SF29ejPLGvKv6nAw Vy/MkeLV49VndhzdvvJ9r5sIgj5hbyZ1/HP1T1H+5YswEQSicj6wbsZfnokEhvdFmPAa h/UZ/3KBjJvVjjUaqL+NP4lhn+gojHIdfTHDoNsuYS9ma3l7TOB3ZE9g6ndk5GqDUi1s 9l+Ut/32yNakTBULvGoBDnbRq/zFkrxn02PqrVWsS8VoTEO7sLJAr1K5S8FiAGXfUFNI euyA== X-Gm-Message-State: ABy/qLbP55B4McpUDTX4YArrD5zV8r5kG9YJoZg7+qHMbQKt/1Y/hC0l 27OxWwDkZfMxW3J/Iy5ToWB7E55BAziYPyJJc0qOz98HW8IfVyMDg+xQy3W4ufk81DEuIgei8L4 1r5FASOQstOyahqcjaRMAyPK3O7RH1lkfYnuVJpwJPvrCET0D4W8EQv8nOAgcWXJJC3dqqrPg2d w= X-Received: by 2002:a67:db19:0:b0:444:3f96:ff70 with SMTP id z25-20020a67db19000000b004443f96ff70mr667239vsj.33.1689964463958; Fri, 21 Jul 2023 11:34:23 -0700 (PDT) X-Received: by 2002:a67:db19:0:b0:444:3f96:ff70 with SMTP id z25-20020a67db19000000b004443f96ff70mr667221vsj.33.1689964463595; Fri, 21 Jul 2023 11:34:23 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id x20-20020a0cb214000000b00626362f1bf1sm1469350qvd.63.2023.07.21.11.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 11:34:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/1] c++: passing partially inst ttp as ttp [PR110566] Date: Fri, 21 Jul 2023 14:34:19 -0400 Message-ID: <20230721183420.1806906-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.376.gcba07a324d In-Reply-To: <0001-c-passing-partially-inst-ttp-as-ttp-PR110566.patch> References: <0001-c-passing-partially-inst-ttp-as-ttp-PR110566.patch> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772056230183870797 X-GMAIL-MSGID: 1772056230183870797 (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)); } /* 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); + 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); + } + 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;