From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id A3D483857716; Mon, 18 Sep 2023 18:27:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3D483857716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695061670; bh=Gpyb6sIYhRaBJG5JqUUCQvffwaHzPB4lwlDds9supy4=; h=From:To:Subject:Date:From; b=tXZ3BBHE8iyX6jPx/p7Gq3gk09euUDHKxwsXaUzJGVZDN8wHkOEEbpm2oBnJNpfZg XJk0M6DuhrtvjAtNZVgCqcMT9kGNCF1pIclDntb3opLulq9MXDJ4RCSL/XboO0uhjV 7WJY7L2fvyelle70qESgfLI+N6aWsvnoZmDTpkjE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4106] c++: optimize tsubst_template_decl for function templates X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 0fb828af75732d39c644fd145c29d41ca14b8cb1 X-Git-Newrev: 094091958654bae07a9ad53a63fd69468efcd3e3 Message-Id: <20230918182750.A3D483857716@sourceware.org> Date: Mon, 18 Sep 2023 18:27:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:094091958654bae07a9ad53a63fd69468efcd3e3 commit r14-4106-g094091958654bae07a9ad53a63fd69468efcd3e3 Author: Patrick Palka Date: Mon Sep 18 14:27:18 2023 -0400 c++: optimize tsubst_template_decl for function templates r14-2655-g92d1425ca78040 made instantiate_template avoid redundantly performing a specialization lookup when calling tsubst_decl. This patch applies the same optimization to the analagous tsubst_template_decl when (partially) instantiating a function template. This allows us to remove an early exit test from register_specialization since we no longer try to register the FUNCTION_DECL corresponding to a function template partial instantiation. gcc/cp/ChangeLog: * pt.cc (register_specialization): Remove now-unnecessary early exit for FUNCTION_DECL partial instantiation. (tsubst_template_decl): Pass use_spec_table=false to tsubst_function_decl. Set DECL_TI_ARGS of a non-lambda FUNCTION_DECL specialization to the full set of arguments. Simplify register_specialization call accordingly. gcc/testsuite/ChangeLog: * g++.dg/template/nontype12.C: Expect two instead of three duplicate diagnostics for A::bar() specialization. Diff: --- gcc/cp/pt.cc | 29 +++++++++-------------------- gcc/testsuite/g++.dg/template/nontype12.C | 3 ++- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index b583c11eb99..a40b8953e62 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1507,21 +1507,6 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, || (TREE_CODE (tmpl) == FIELD_DECL && TREE_CODE (spec) == NONTYPE_ARGUMENT_PACK)); - if (TREE_CODE (spec) == FUNCTION_DECL - && uses_template_parms (DECL_TI_ARGS (spec))) - /* This is the FUNCTION_DECL for a partial instantiation. Don't - register it; we want the corresponding TEMPLATE_DECL instead. - We use `uses_template_parms (DECL_TI_ARGS (spec))' rather than - the more obvious `uses_template_parms (spec)' to avoid problems - with default function arguments. In particular, given - something like this: - - template void f(T t1, T t = T()) - - the default argument expression is not substituted for in an - instantiation unless and until it is actually needed. */ - return spec; - spec_entry elt; elt.tmpl = tmpl; elt.args = args; @@ -14665,7 +14650,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, tree in_decl = t; tree spec; tree tmpl_args; - tree full_args; + tree full_args = NULL_TREE; tree r; hashval_t hash = 0; @@ -14756,7 +14741,8 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, tree inner = decl; ++processing_template_decl; if (TREE_CODE (inner) == FUNCTION_DECL) - inner = tsubst_function_decl (inner, args, complain, lambda_fntype); + inner = tsubst_function_decl (inner, args, complain, lambda_fntype, + /*use_spec_table=*/false); else { if (TREE_CODE (inner) == TYPE_DECL && !TYPE_DECL_ALIAS_P (inner)) @@ -14794,6 +14780,11 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, } else { + if (TREE_CODE (inner) == FUNCTION_DECL) + /* Set DECL_TI_ARGS to the full set of template arguments, which + tsubst_function_decl didn't do due to use_spec_table=false. */ + DECL_TI_ARGS (inner) = full_args; + DECL_TI_TEMPLATE (inner) = r; DECL_TI_ARGS (r) = DECL_TI_ARGS (inner); } @@ -14824,9 +14815,7 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, if (TREE_CODE (decl) == FUNCTION_DECL && !lambda_fntype) /* Record this non-type partial instantiation. */ - register_specialization (r, t, - DECL_TI_ARGS (DECL_TEMPLATE_RESULT (r)), - false, hash); + register_specialization (r, t, full_args, false, hash); return r; } diff --git a/gcc/testsuite/g++.dg/template/nontype12.C b/gcc/testsuite/g++.dg/template/nontype12.C index 9a9c3ac1e66..a0e70181862 100644 --- a/gcc/testsuite/g++.dg/template/nontype12.C +++ b/gcc/testsuite/g++.dg/template/nontype12.C @@ -5,7 +5,8 @@ template struct A { template int foo(); // { dg-error "double" "" { target c++17_down } } template class> int bar(); // { dg-bogus {double[^\n]*\n[^\n]*C:7:[^\n]*double} "" { xfail c++17_down } } - // { dg-error "double" "" { target c++17_down } .-1 } + // The above xfailed dg-bogus test means that we issue two errors + // for the invalid 'double' NTTP, and preferably we'd issue just one. template struct X; // { dg-error "double" "" { target c++17_down } } };