From c4bff4c230c8d3414bc77f7a58ffc5f61b6bd08c Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 14 May 2020 06:39:29 -0700 Subject: [PATCH] c++: Improve build_template_decl I discovered all the users of build_template_decl were explicitly setting the RESULT and TYPE fields of the built decl. Let's just have build_template_decl do that in the first place. * pt.c (build_template_decl): Init DECL_TEMPLATE_RESULT & TREE_TYPE here ... (process_partial_specialization): ... not here ... (push_template_decl_real, add_inherited_template_parms) (build_deduction_guide): ... or here. --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/pt.c | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5f5b31b2474..45b60de120b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2020-05-14 Nathan Sidwell + + * pt.c (build_template_decl): Init DECL_TEMPLATE_RESULT & + TREE_TYPE here ... + (process_partial_specialization): ... not here ... + (push_template_decl_real, add_inherited_template_parms) + (build_deduction_guide): ... or here. + 2020-05-14 Jakub Jelinek * cp-gimplify.c (cp_genericize_r): Set cfun->has_omp_target. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a36f603761c..837644f8e6c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4883,7 +4883,9 @@ build_template_decl (tree decl, tree parms, bool member_template_p) tree tmpl = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), NULL_TREE); SET_DECL_LANGUAGE (tmpl, DECL_LANGUAGE (decl)); DECL_TEMPLATE_PARMS (tmpl) = parms; + DECL_TEMPLATE_RESULT (tmpl) = decl; DECL_CONTEXT (tmpl) = DECL_CONTEXT (decl); + TREE_TYPE (tmpl) = TREE_TYPE (decl); DECL_SOURCE_LOCATION (tmpl) = DECL_SOURCE_LOCATION (decl); DECL_MEMBER_TEMPLATE_P (tmpl) = member_template_p; @@ -5233,8 +5235,6 @@ process_partial_specialization (tree decl) // Build the template decl. tree tmpl = build_template_decl (decl, current_template_parms, DECL_MEMBER_TEMPLATE_P (maintmpl)); - TREE_TYPE (tmpl) = type; - DECL_TEMPLATE_RESULT (tmpl) = decl; SET_DECL_TEMPLATE_SPECIALIZATION (tmpl); DECL_TEMPLATE_INFO (tmpl) = build_template_info (maintmpl, specargs); DECL_PRIMARY_TEMPLATE (tmpl) = maintmpl; @@ -5908,8 +5908,6 @@ push_template_decl_real (tree decl, bool is_friend) new_tmpl = build_template_decl (decl, current_template_parms, member_template_p); - DECL_TEMPLATE_RESULT (new_tmpl) = decl; - TREE_TYPE (new_tmpl) = TREE_TYPE (decl); DECL_TI_TEMPLATE (decl) = new_tmpl; SET_DECL_TEMPLATE_SPECIALIZATION (new_tmpl); DECL_TEMPLATE_INFO (new_tmpl) @@ -5979,8 +5977,7 @@ push_template_decl_real (tree decl, bool is_friend) } } - DECL_TEMPLATE_RESULT (tmpl) = decl; - TREE_TYPE (tmpl) = TREE_TYPE (decl); + gcc_checking_assert (DECL_TEMPLATE_RESULT (tmpl) == decl); /* Push template declarations for global functions and types. Note that we do not try to push a global template friend declared in a @@ -6085,8 +6082,6 @@ add_inherited_template_parms (tree fn, tree inherited) tree tmpl = build_template_decl (fn, parms, /*member*/true); tree args = template_parms_to_args (parms); DECL_TEMPLATE_INFO (fn) = build_template_info (tmpl, args); - TREE_TYPE (tmpl) = TREE_TYPE (fn); - DECL_TEMPLATE_RESULT (tmpl) = fn; DECL_ARTIFICIAL (tmpl) = true; DECL_PRIMARY_TEMPLATE (tmpl) = tmpl; return tmpl; @@ -28314,8 +28309,6 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com DECL_NONCONVERTING_P (ded_fn) = explicit_p; tree ded_tmpl = build_template_decl (ded_fn, tparms, /*member*/false); DECL_ARTIFICIAL (ded_tmpl) = true; - DECL_TEMPLATE_RESULT (ded_tmpl) = ded_fn; - TREE_TYPE (ded_tmpl) = TREE_TYPE (ded_fn); DECL_TEMPLATE_INFO (ded_fn) = build_template_info (ded_tmpl, targs); DECL_PRIMARY_TEMPLATE (ded_tmpl) = ded_tmpl; if (DECL_P (ctor)) -- 2.43.5