Skip to content

Commit f40d24c

Browse files
committed
c++: maybe_substitute_reqs_for fix
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.
1 parent 810bcc0 commit f40d24c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

gcc/cp/constraint.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ maybe_substitute_reqs_for (tree reqs, const_tree decl)
13391339
if (DECL_UNIQUE_FRIEND_P (decl) && DECL_TEMPLATE_INFO (decl))
13401340
{
13411341
tree tmpl = DECL_TI_TEMPLATE (decl);
1342-
tree outer_args = outer_template_args (tmpl);
1342+
tree outer_args = outer_template_args (decl);
13431343
processing_template_decl_sentinel s;
13441344
if (PRIMARY_TEMPLATE_P (tmpl)
13451345
|| uses_template_parms (outer_args))

gcc/cp/cp-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7083,7 +7083,7 @@ extern tree maybe_set_retval_sentinel (void);
70837083
extern tree template_parms_to_args (tree);
70847084
extern tree template_parms_level_to_args (tree);
70857085
extern tree generic_targs_for (tree);
7086-
extern tree outer_template_args (tree);
7086+
extern tree outer_template_args (const_tree);
70877087

70887088
/* in expr.cc */
70897089
extern tree cplus_expand_constant (tree);

gcc/cp/pt.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4966,19 +4966,21 @@ generic_targs_for (tree tmpl)
49664966
}
49674967

49684968
/* Return the template arguments corresponding to the template parameters of
4969-
TMPL's enclosing scope. When TMPL is a member of a partial specialization,
4969+
DECL's enclosing scope. When DECL is a member of a partial specialization,
49704970
this returns the arguments for the partial specialization as opposed to those
49714971
for the primary template, which is the main difference between this function
4972-
and simply using e.g. the TYPE_TI_ARGS of TMPL's DECL_CONTEXT. */
4972+
and simply using e.g. the TYPE_TI_ARGS of DECL's DECL_CONTEXT. */
49734973

49744974
tree
4975-
outer_template_args (tree tmpl)
4975+
outer_template_args (const_tree decl)
49764976
{
4977-
tree ti = get_template_info (DECL_TEMPLATE_RESULT (tmpl));
4977+
if (TREE_CODE (decl) == TEMPLATE_DECL)
4978+
decl = DECL_TEMPLATE_RESULT (decl);
4979+
tree ti = get_template_info (decl);
49784980
if (!ti)
49794981
return NULL_TREE;
49804982
tree args = TI_ARGS (ti);
4981-
if (!PRIMARY_TEMPLATE_P (tmpl))
4983+
if (!PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)))
49824984
return args;
49834985
if (TMPL_ARGS_DEPTH (args) == 1)
49844986
return NULL_TREE;

0 commit comments

Comments
 (0)