aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/name-lookup.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-06 23:46:53 -0400
committerJason Merrill <jason@redhat.com>2022-04-08 21:50:46 -0400
commit58586721c79f77224b8571a5dba732620d5546ab (patch)
treef6d8b7e5f5c980c13ff8c6c92e4c65693839de2d /gcc/cp/name-lookup.cc
parent405eda0d34b69fb6ee12ba6ed0f69c2c2411d8ee (diff)
downloadgcc-58586721c79f77224b8571a5dba732620d5546ab.zip
gcc-58586721c79f77224b8571a5dba732620d5546ab.tar.gz
gcc-58586721c79f77224b8571a5dba732620d5546ab.tar.bz2
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.
Diffstat (limited to 'gcc/cp/name-lookup.cc')
-rw-r--r--gcc/cp/name-lookup.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index b7fc278..118da09 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5898,6 +5898,7 @@ set_decl_namespace (tree decl, tree scope, bool friendp)
tree found = NULL_TREE;
bool hidden_p = false;
+ bool saw_template = false;
for (lkp_iterator iter (old); iter; ++iter)
{
@@ -5922,6 +5923,20 @@ set_decl_namespace (tree decl, tree scope, bool friendp)
found = ofn;
hidden_p = iter.hidden_p ();
}
+ else if (TREE_CODE (decl) == FUNCTION_DECL
+ && TREE_CODE (ofn) == TEMPLATE_DECL)
+ saw_template = true;
+ }
+
+ if (!found && friendp && saw_template)
+ {
+ /* "[if no non-template match is found,] each remaining function template
+ is replaced with the specialization chosen by deduction from the
+ friend declaration or discarded if deduction fails."
+
+ So tell check_explicit_specialization to look for a match. */
+ SET_DECL_IMPLICIT_INSTANTIATION (decl);
+ return;
}
if (found)