2018-12-06 Alexandre Oliva PR c++/86747 * pt.c (tsubst_friend_class): Enter tsubsted class context. --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -10558,7 +10558,10 @@ tsubst_friend_class (tree friend_tmpl, tree args) if (TREE_CODE (context) == NAMESPACE_DECL) push_nested_namespace (context); else - push_nested_class (context); + { + context = tsubst (context, args, tf_error, NULL_TREE); + push_nested_class (context); + } tmpl = lookup_name_real (DECL_NAME (friend_tmpl), /*prefer_type=*/false, /*non_class=*/false, /*block_p=*/false, --- /dev/null +++ gcc/testsuite/g++.dg/pr86747.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +template class A { + template class C; // #1 + template friend class C; // #2 +}; + +A a;