public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3494] c++: Adjust synthetic template parm creation Date: Tue, 25 Oct 2022 20:12:32 +0000 (GMT) [thread overview] Message-ID: <20221025201232.7388F3857818@sourceware.org> (raw) https://gcc.gnu.org/g:43e654afeba484d75fbee080262a038c1da00ad5 commit r13-3494-g43e654afeba484d75fbee080262a038c1da00ad5 Author: Nathan Sidwell <nathan@acm.org> Date: Tue Oct 25 09:39:00 2022 -0400 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. Diff: --- gcc/cp/parser.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a39c5f0d24b..e685f190b3d 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);
reply other threads:[~2022-10-25 20:12 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221025201232.7388F3857818@sourceware.org \ --to=nathan@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).