c++: friend implicit template instantiation [PR91618]
authorJason Merrill <jason@redhat.com>
Thu, 7 Apr 2022 03:46:53 +0000 (23:46 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 9 Apr 2022 01:50:46 +0000 (21:50 -0400)
commit58586721c79f77224b8571a5dba732620d5546ab
treef6d8b7e5f5c980c13ff8c6c92e4c65693839de2d
parent405eda0d34b69fb6ee12ba6ed0f69c2c2411d8ee
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.
gcc/cp/decl2.cc
gcc/cp/name-lookup.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/friend7.C
gcc/testsuite/g++.dg/template/friend72.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/friend72a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/friend73.C [new file with mode: 0644]