https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96604
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jason Merrill <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:58586721c79f77224b8571a5dba732620d5546ab commit r12-8065-g58586721c79f77224b8571a5dba732620d5546ab Author: Jason Merrill <ja...@redhat.com> Date: Wed Apr 6 23:46:53 2022 -0400 c++: friend implicit template instantiation [PR91618] This rule that for a friend with a qualified name we try to find a matching template was already in C++98, but it seems we never implemented it, and nobody reported it until 2019. This patch sets DECL_IMPLICIT_INSTANTIATION to signal to check_explicit_specialization that we want to find a template, like grokfndecl already did for explicit template args. check_classfn also needs to call it, as check_classfn is called after the call to check_explicit_specialization in grokfndecl, whereas the call to set_decl_namespace comes sooner. This inconsistency is inelegant, but safer at this point in the release cycle; I'll unify them in stage 1. PR c++/91618 PR c++/96604 gcc/cp/ChangeLog: * name-lookup.cc (set_decl_namespace): Set DECL_IMPLICIT_INSTANTIATION if no non-template match. * pt.cc (check_explicit_specialization): Check it. * decl2.cc (check_classfn): Call it. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/friend7.C: Remove xfail. * g++.dg/template/friend72.C: New test. * g++.dg/template/friend72a.C: New test. * g++.dg/template/friend73.C: New test.