From patchwork Wed Mar 15 12:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 70190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2306750wrd; Wed, 15 Mar 2023 05:46:05 -0700 (PDT) X-Google-Smtp-Source: AK7set/f1QrscjBJ5qWYLTevptY2gP/FxP2ZbH6DpAtw1oZH48QomOV4A0PLVrmf9ETJjpFqi5o3 X-Received: by 2002:aa7:d756:0:b0:4fa:315a:cb55 with SMTP id a22-20020aa7d756000000b004fa315acb55mr2743027eds.21.1678884364929; Wed, 15 Mar 2023 05:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678884364; cv=none; d=google.com; s=arc-20160816; b=E3tytxjzpZKC8JqSVeX4QLdTnNw/GRl2462lBIKvVXQB2Ex6c+yh5JiBV21jcFA4I3 B4c8F3HyC1dg4yULugXAPMZGjFFVJ/alO2ob/n3VkBHrYRx+xypcc0YH3ym+PotWMeif H26PBg/4ChZPGFnIGTQzd0bi0WVp0mm6kh7kZE2SMlVkqQU0HtUgxxa6fSzjAhgc45BK W1eRSNkog9C4K6Xq0qfkefDtH4AcvhnqXTLICCWqn4Ni1dlA9cpnkGXQSOmS0DIU+ImJ LL3UBsud7+eecXE7w+AP1RcjGjlA0GKspyzZykgwiWCiWct581L7VlsyDMV161S2hwgv Do7Q== 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:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=+HNTAGmdjQ7gJCMEFahoIfTdKl4JNR08YoUFE61rqMw=; b=oJ1a69/KkXOMxVHT81jvTauHW0RHnYL5p24amKK9vPNUoJZgAEwQwOVkAJ+GOB6x54 menibpDpf8LsZiSxvsSPCEvKVFcy0m4eUYQku7Sj0gU0aDD+CFLk6p6wFVMhN9ZScs4W PksRbNMqL/mWbIbiuf4/Cn8+FH53z5IQiB6b7DgyCdUeBiJTK7JPuffyJuTZdX/jr+Sq wULQkldtZEJ3tMYFd66Umyk1JX+lxY87AbkuJPZqEctPCs5VWKBWzJ1WSa6r8Fjv+sMK xI+SXq+MjfSPqZfvmW2PaV6LVN2DdtEaSz0Vm6rkKDB/+pMq2lAKwWFMhZt9GiMl38jh NXoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OuHXGFdK; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w16-20020a056402071000b004acc42357cfsi4274955edx.364.2023.03.15.05.46.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 05:46:04 -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=OuHXGFdK; 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 D4CCE385B51A for ; Wed, 15 Mar 2023 12:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4CCE385B51A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678884337; bh=+HNTAGmdjQ7gJCMEFahoIfTdKl4JNR08YoUFE61rqMw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OuHXGFdKPKc7iA9XGfpxrhfSYFzVf83As+jbi5PD1JOa7eIdQmn/oyAmI1pmGy6v2 gtZfSPi5ipyZ7sP7XgRq2bzh3e4gUHwV6zoQFC1sAlgCW6WoGJarDYyonFe2AYG5q2 KH2k8v2qv83IhqkcVqIiepRWw5x7SRjJRPIyskN8= 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 4CE583857C48 for ; Wed, 15 Mar 2023 12:44:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CE583857C48 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-ChUNtxp0PWybMggGb71c6Q-1; Wed, 15 Mar 2023 08:44:32 -0400 X-MC-Unique: ChUNtxp0PWybMggGb71c6Q-1 Received: by mail-qv1-f69.google.com with SMTP id f8-20020a0cbec8000000b005b14a30945cso438063qvj.8 for ; Wed, 15 Mar 2023 05:44:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678884271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+HNTAGmdjQ7gJCMEFahoIfTdKl4JNR08YoUFE61rqMw=; b=PhWemT8udfRqe/qXzzsuPT+VzyBN9V+MOy6gLInuRIqJ8NNWoR9vPNDaD/jp0C1j+3 s4nM3qQQRkRtUXYKVLWAzUjcoNT1TMV9zA1K3nAX0KoJ4QL7IRjVpK1ye65ZixL4MazM slaSipX7X9g25URlWbsIVORVODKlFVMkI+/zJ9Gi3UCbfiWsY1hWN00VAeQeFYmIkCU7 KmLYGHsJilSH9LO/1nIa1k2XmUQYFJSKkS4Gyg1VnL52Q9YTyydjkfS0T6X9XBtEd3Ok QSLV415x9xVyBXc95ZZ/vSa8jHZ5eCjVpQ3fGTCdV5lqKneOzXt170w8w5d9f8dOLfcx ecUg== X-Gm-Message-State: AO0yUKVOMX+3Piqk9gwIri2I5uv6PBK2UYaoqjhepiD6RDY2+Gl+ff65 VytsAn7jATmZKpwohJAYStBKobe292008lFQ37uUpeLCk3AzGVTe96lGlw0WgB501IlJhzB0pSN 8jU23wJMPGBNbQSjP8vV0Oc1VHoO1S8pEivjyhPZbRkmphoMXCyW/FF3tj5Ir3gxTeaUBmMxcWg == X-Received: by 2002:ac8:5715:0:b0:3b9:bc8c:c1f8 with SMTP id 21-20020ac85715000000b003b9bc8cc1f8mr29917419qtw.3.1678884271464; Wed, 15 Mar 2023 05:44:31 -0700 (PDT) X-Received: by 2002:ac8:5715:0:b0:3b9:bc8c:c1f8 with SMTP id 21-20020ac85715000000b003b9bc8cc1f8mr29917372qtw.3.1678884271037; Wed, 15 Mar 2023 05:44:31 -0700 (PDT) Received: from jason.cygnus.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id 133-20020a370c8b000000b00745793b5fa5sm3749368qkm.45.2023.03.15.05.44.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 05:44:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++: passing one ttp to another [PR108179] Date: Wed, 15 Mar 2023 08:44:27 -0400 Message-Id: <20230315124427.687003-2-jason@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230315124427.687003-1-jason@redhat.com> References: <20230315124427.687003-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760437851932084730?= X-GMAIL-MSGID: =?utf-8?q?1760437851932084730?= I kept trying to improve our choice of how many levels of outer_args to add, when really the problem was that outer_args are for PARM and for this reverse deduction we should be adding the outer arguments for ARG. I spent quite a while trying to get DECL_CONTEXT set consistently on template template parameters that have gone through reduce_template_parm_level before I realized I could just use current_scope(). PR c++/108179 PR c++/104107 PR c++/95036 gcc/cp/ChangeLog: * pt.cc (coerce_template_template_parms): Use args from DECL_CONTEXT (arg_tmpl) instead of outer_args. gcc/testsuite/ChangeLog: * g++.dg/template/ttp35.C: New test. --- gcc/cp/pt.cc | 32 ++++++++++++++------------- gcc/testsuite/g++.dg/template/ttp35.C | 7 ++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/ttp35.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c9cd9f6097d..1b2a250224e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -8084,22 +8084,24 @@ coerce_template_template_parms (tree parm_tmpl, tree pargs = template_parms_level_to_args (parm_parms); - /* PARM, and thus the context in which we are passing ARG to it, may be - at a deeper level than ARG; when trying to coerce to ARG_PARMS, we - want to provide the right number of levels, so we reduce the number of - levels in OUTER_ARGS before prepending them. This is most important - when ARG is a namespace-scope template, as in alias-decl-ttp2.C. + /* PARM and ARG might be at different template depths, and we want to + pass the right additional levels of args when coercing PARGS to + ARG_PARMS in case we need to do any substitution into non-type + template parameter types. - ARG might also be deeper than PARM (ttp23). In that case, we include - all of OUTER_ARGS. The missing levels seem potentially problematic, - but I can't come up with a testcase that breaks. */ - if (int arg_outer_levs = TMPL_PARMS_DEPTH (arg_parms_full) - 1) - { - auto x = make_temp_override (TREE_VEC_LENGTH (outer_args)); - if (TMPL_ARGS_DEPTH (outer_args) > arg_outer_levs) - TREE_VEC_LENGTH (outer_args) = arg_outer_levs; - pargs = add_to_template_args (outer_args, pargs); - } + 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. */ + 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); + pargs = add_to_template_args (scope_args, pargs); pargs = coerce_template_parms (arg_parms, pargs, NULL_TREE, tf_none); if (pargs != error_mark_node) diff --git a/gcc/testsuite/g++.dg/template/ttp35.C b/gcc/testsuite/g++.dg/template/ttp35.C new file mode 100644 index 00000000000..4847ea46ae1 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp35.C @@ -0,0 +1,7 @@ +// PR c++/108179 + +template class F> +struct Foo {}; + +template class F> +void f(Foo) {}