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 4CE583857C48 for ; Wed, 15 Mar 2023 12:44:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CE583857C48 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=1678884273; 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=+HNTAGmdjQ7gJCMEFahoIfTdKl4JNR08YoUFE61rqMw=; b=eV6gdU+vu2OqM8I3+B8ngo7bxFPSFc8r+sdATRQC6y9ji3xKn3kO3HMzgC/bvrCcJNewdD NQKSFxVN8ROtiM0axpktAh8VytnPCtiv3gHjsr1eWBuQqkMucvORs1RcZviioeVxHUPgJh w/IYnUDq281uKGYMDeda3m9I/yil5FY= 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-Google-Smtp-Source: AK7set9M8TPM3PG6JFLWL67d/tn/nfp2MR5fcz2qSnC5QNWgPUIEvkW6weEdDTYkzPxMHa9fTyCBLg== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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) {} -- 2.31.1