From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed 2/2] c++: maybe_substitute_reqs_for fix
Date: Tue, 22 Aug 2023 14:36:39 -0400 [thread overview]
Message-ID: <20230822183639.1425752-2-jason@redhat.com> (raw)
In-Reply-To: <20230822183639.1425752-1-jason@redhat.com>
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
While working on PR109751 I found that maybe_substitute_reqs_for was doing
the wrong thing for a non-template friend, substituting in the template args
of the scope's original template rather than those of the instantiation.
This didn't end up being necessary to fix the PR, but it's still an
improvement.
gcc/cp/ChangeLog:
* pt.cc (outer_template_args): Handle non-template argument.
* constraint.cc (maybe_substitute_reqs_for): Pass decl to it.
* cp-tree.h (outer_template_args): Adjust.
---
gcc/cp/cp-tree.h | 2 +-
gcc/cp/constraint.cc | 2 +-
gcc/cp/pt.cc | 12 +++++++-----
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 356d7ffb6d6..eb901683b6d 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7083,7 +7083,7 @@ extern tree maybe_set_retval_sentinel (void);
extern tree template_parms_to_args (tree);
extern tree template_parms_level_to_args (tree);
extern tree generic_targs_for (tree);
-extern tree outer_template_args (tree);
+extern tree outer_template_args (const_tree);
/* in expr.cc */
extern tree cplus_expand_constant (tree);
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8cf0f2d0974..c9e4e7043cd 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -1339,7 +1339,7 @@ maybe_substitute_reqs_for (tree reqs, const_tree decl)
if (DECL_UNIQUE_FRIEND_P (decl) && DECL_TEMPLATE_INFO (decl))
{
tree tmpl = DECL_TI_TEMPLATE (decl);
- tree outer_args = outer_template_args (tmpl);
+ tree outer_args = outer_template_args (decl);
processing_template_decl_sentinel s;
if (PRIMARY_TEMPLATE_P (tmpl)
|| uses_template_parms (outer_args))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index f4e77d172b9..c017591f235 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -4966,19 +4966,21 @@ generic_targs_for (tree tmpl)
}
/* Return the template arguments corresponding to the template parameters of
- TMPL's enclosing scope. When TMPL is a member of a partial specialization,
+ DECL's enclosing scope. When DECL is a member of a partial specialization,
this returns the arguments for the partial specialization as opposed to those
for the primary template, which is the main difference between this function
- and simply using e.g. the TYPE_TI_ARGS of TMPL's DECL_CONTEXT. */
+ and simply using e.g. the TYPE_TI_ARGS of DECL's DECL_CONTEXT. */
tree
-outer_template_args (tree tmpl)
+outer_template_args (const_tree decl)
{
- tree ti = get_template_info (DECL_TEMPLATE_RESULT (tmpl));
+ if (TREE_CODE (decl) == TEMPLATE_DECL)
+ decl = DECL_TEMPLATE_RESULT (decl);
+ tree ti = get_template_info (decl);
if (!ti)
return NULL_TREE;
tree args = TI_ARGS (ti);
- if (!PRIMARY_TEMPLATE_P (tmpl))
+ if (!PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)))
return args;
if (TMPL_ARGS_DEPTH (args) == 1)
return NULL_TREE;
--
2.39.3
prev parent reply other threads:[~2023-08-22 18:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 18:36 [pushed 1/2] c++: constrained hidden friends [PR109751] Jason Merrill
2023-08-22 18:36 ` Jason Merrill [this message]
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=20230822183639.1425752-2-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@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: link
Be 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).