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.
pushed to master.
nathan
--
Nathan Sidwell
2020-05-14 Nathan Sidwell <nat...@acm.org>
* 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.
diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c
index a36f603761c..5ca659e9f28 100644
--- i/gcc/cp/pt.c
+++ w/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,6 +5977,5 @@ 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);
@@ -6085,8 +6090,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 +28312,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))