aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-10-20 14:13:10 -0400
committerPatrick Palka <ppalka@redhat.com>2022-10-20 14:13:10 -0400
commit14272aec22dcacbb3b937d6c5b86794faaa24620 (patch)
tree80570cdfc04695bc11f437ce0c264839a0235519 /gcc/cp
parent1d561e1851c466a4952081caef17747781609b00 (diff)
downloadgcc-14272aec22dcacbb3b937d6c5b86794faaa24620.zip
gcc-14272aec22dcacbb3b937d6c5b86794faaa24620.tar.gz
gcc-14272aec22dcacbb3b937d6c5b86794faaa24620.tar.bz2
c++: constraint matching, TEMPLATE_ID_EXPR, current inst
Here we're crashing during constraint matching for the instantiated hidden friends due to two issues with dependent substitution into a TEMPLATE_ID_EXPR that names a template from the current instantiation (as for C<1> with T=T from maybe_substitute_reqs_for): * tsubst_copy substitutes into such a TEMPLATE_DECL by looking it up from the substituted class scope. But for this lookup to work when the args are dependent, we need to substitute the class scope with entering_scope=true so that we obtain the primary template type A<T> (which has TYPE_BINFO) instead of the implicit instantiation A<T> (which doesn't). * lookup_and_finish_template_variable shouldn't instantiate a TEMPLATE_ID_EXPR that names a TEMPLATE_DECL which has more than one level of (unsubstituted) parameters (such as A<T>::C). gcc/cp/ChangeLog: * pt.cc (lookup_and_finish_template_variable): Don't instantiate if the template's scope is dependent. (tsubst_copy) <case TEMPLATE_DECL>: Pass entering_scope=true when substituting the class scope. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-friend10.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/pt.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 5eddad9..1289aab 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10398,14 +10398,15 @@ tree
lookup_and_finish_template_variable (tree templ, tree targs,
tsubst_flags_t complain)
{
- templ = lookup_template_variable (templ, targs);
- if (!any_dependent_template_arguments_p (targs))
+ tree var = lookup_template_variable (templ, targs);
+ if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) == 1
+ && !any_dependent_template_arguments_p (targs))
{
- templ = finish_template_variable (templ, complain);
- mark_used (templ);
+ var = finish_template_variable (var, complain);
+ mark_used (var);
}
- return convert_from_reference (templ);
+ return convert_from_reference (var);
}
/* If the set of template parameters PARMS contains a template parameter
@@ -17229,7 +17230,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
TEMPLATE_DECL with `D<T>' as its DECL_CONTEXT. Now we
have to substitute this with one having context `D<int>'. */
- tree context = tsubst (DECL_CONTEXT (t), args, complain, in_decl);
+ tree context = tsubst_aggr_type (DECL_CONTEXT (t), args, complain,
+ in_decl, /*entering_scope=*/true);
return lookup_field (context, DECL_NAME(t), 0, false);
}
else