From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 5528A3858C27; Wed, 15 Mar 2023 12:45:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5528A3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678884315; bh=7eOYWPFpGP+c8w1cT4FDhIkjEdpurGF07rKGnkbn3MU=; h=From:To:Subject:Date:From; b=siArzjkaPxaXME+wXih8NTpvHW13aBHkp/51vbAfWlUf8ZUsuYmSIJ/I7BmF3PdF+ Hv6nHpaSvJx1+aa0J8l5Mg8JNAPSb53TIadHl4iZfKl6yG3tnqus/IvsGPxLYli3wi ElqdVu0Tsr5p/UbMKVLXQMW/IRUv5AMTAtO57rIw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6693] c++: passing one ttp to another [PR108179] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 5ccbf162511b896672a72934c3cafd37a42d6438 X-Git-Newrev: 3ea64aad06a2b32739028bae03b9b9a5691d2d30 Message-Id: <20230315124515.5528A3858C27@sourceware.org> Date: Wed, 15 Mar 2023 12:45:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3ea64aad06a2b32739028bae03b9b9a5691d2d30 commit r13-6693-g3ea64aad06a2b32739028bae03b9b9a5691d2d30 Author: Jason Merrill Date: Fri Mar 10 14:55:27 2023 -0500 c++: passing one ttp to another [PR108179] 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. Diff: --- gcc/cp/pt.cc | 32 +++++++++++++++++--------------- gcc/testsuite/g++.dg/template/ttp35.C | 7 +++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index d75c4395c8a..ddbd73371b9 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -8110,22 +8110,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) {}