aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-10-25 09:39:00 -0400
committerNathan Sidwell <nathan@acm.org>2022-10-25 15:16:22 -0400
commit43e654afeba484d75fbee080262a038c1da00ad5 (patch)
treeba3b9cc0bc14981159ac43691e5dd0fdd293e103 /gcc/cp
parentfe1e1ae0c84d3f52f62509d164bbb117c29d9675 (diff)
downloadgcc-43e654afeba484d75fbee080262a038c1da00ad5.zip
gcc-43e654afeba484d75fbee080262a038c1da00ad5.tar.gz
gcc-43e654afeba484d75fbee080262a038c1da00ad5.tar.bz2
c++: Adjust synthetic template parm creation
We intend to mark synthetic template parameters (coming from use of auto parms), as DECL_VIRTUAL_P. The API of process_template_parm is awkwardly confusing, and we were marking the previous template parm (unless this was the first parm). process_template_parm returns the list of parms, when most (all?) users really want the newly-added final node. That's a bigger change, so let's not do it right now. With this, we correctly mark such synthetic parms DECL_VIRTUAL_P. gcc/cp/ * parser.cc (synthesize_implicit_template_parm): Fix thinko about mark the new parm DECL_VIRTUAL_P. Avoid unneccessary tree_last call.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/parser.cc26
1 files changed, 15 insertions, 11 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index a39c5f0..e685f19 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -48996,12 +48996,11 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr)
tree proto = constr ? DECL_INITIAL (constr) : NULL_TREE;
tree synth_id = make_generic_type_name ();
- tree synth_tmpl_parm;
bool non_type = false;
/* Synthesize the type template parameter. */
gcc_assert(!proto || TREE_CODE (proto) == TYPE_DECL);
- synth_tmpl_parm = finish_template_type_parm (class_type_node, synth_id);
+ tree synth_tmpl_parm = finish_template_type_parm (class_type_node, synth_id);
if (become_template)
current_template_parms = tree_cons (size_int (current_template_depth + 1),
@@ -49016,22 +49015,27 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr)
node,
/*non_type=*/non_type,
/*param_pack=*/false);
+ // Process_template_parm returns the list of parms, and
+ // parser->implicit_template_parms holds the final node of the parm
+ // list. We really want to manipulate the newly appended element.
+ gcc_checking_assert (!parser->implicit_template_parms
+ || parser->implicit_template_parms == new_parm);
+ if (parser->implicit_template_parms)
+ new_parm = TREE_CHAIN (new_parm);
+ gcc_checking_assert (!TREE_CHAIN (new_parm));
+
+ // Record the last implicit parm node
+ parser->implicit_template_parms = new_parm;
/* Mark the synthetic declaration "virtual". This is used when
comparing template-heads to determine if whether an abbreviated
function template is equivalent to an explicit template.
- Note that DECL_ARTIFICIAL is used elsewhere for template parameters. */
+ Note that DECL_ARTIFICIAL is used elsewhere for template
+ parameters. */
if (TREE_VALUE (new_parm) != error_mark_node)
DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true;
- // Chain the new parameter to the list of implicit parameters.
- if (parser->implicit_template_parms)
- parser->implicit_template_parms
- = TREE_CHAIN (parser->implicit_template_parms);
- else
- parser->implicit_template_parms = new_parm;
-
tree new_decl = get_local_decls ();
if (non_type)
/* Return the TEMPLATE_PARM_INDEX, not the PARM_DECL. */
@@ -49059,7 +49063,7 @@ synthesize_implicit_template_parm (cp_parser *parser, tree constr)
/* If the new parameter was constrained, we need to add that to the
constraints in the template parameter list. */
- if (tree req = TEMPLATE_PARM_CONSTRAINTS (tree_last (new_parm)))
+ if (tree req = TEMPLATE_PARM_CONSTRAINTS (new_parm))
{
tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
reqs = combine_constraint_expressions (reqs, req);