tree pushed_scope = push_scope (ctype);
tree matched = NULL_TREE;
tree fns = get_class_binding (ctype, DECL_NAME (function));
-
+ bool saw_template = false;
+
for (ovl_iterator iter (fns); !matched && iter; ++iter)
{
tree fndecl = *iter;
+ if (TREE_CODE (fndecl) == TEMPLATE_DECL)
+ saw_template = true;
+
/* A member template definition only matches a member template
declaration. */
if (is_template != (TREE_CODE (fndecl) == TEMPLATE_DECL))
matched = fndecl;
}
+ if (!matched && !is_template && saw_template
+ && !processing_template_decl && DECL_UNIQUE_FRIEND_P (function))
+ {
+ /* "[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 ask check_explicit_specialization to find a matching template. */
+ SET_DECL_IMPLICIT_INSTANTIATION (function);
+ tree spec = check_explicit_specialization (DECL_NAME (function),
+ function, /* tcount */0,
+ /* friend flag */4,
+ /* attrlist */NULL_TREE);
+ if (spec != error_mark_node)
+ matched = spec;
+ }
+
if (!matched)
{
if (!COMPLETE_TYPE_P (ctype))
tree found = NULL_TREE;
bool hidden_p = false;
+ bool saw_template = false;
for (lkp_iterator iter (old); iter; ++iter)
{
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)
specialization = 1;
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
}
- else if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR)
+ else if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR
+ || (DECL_LANG_SPECIFIC (decl)
+ && DECL_IMPLICIT_INSTANTIATION (decl)))
{
if (is_friend)
/* This could be something like:
friend class __attribute__((deprecated)) N3;
[[deprecated]] friend void foo<>(int, int); // { dg-warning "attribute ignored" }
[[deprecated]] friend void ::foo(int, int); // { dg-warning "attribute ignored" }
- // { dg-bogus "should have" "PR100339" { xfail *-*-* } .-1 }
+ // { dg-bogus "should have" "PR100339" }
};
template<typename T>
--- /dev/null
+// PR c++/91618
+// { dg-do link }
+
+template <class T> int f(T t)
+{ return t.i; }
+
+class A {
+ friend int ::f(A);
+ int i;
+};
+
+int main()
+{
+ f(A()); // link error, trying to call non-template function
+}
--- /dev/null
+// PR c++/91618
+
+template <class T> int f(T t, int)
+{ return t.i; }
+
+class A {
+ friend int ::f(A); // { dg-error "" }
+ int i;
+};
+
+int main()
+{
+ f(A()); // { dg-error "no match" }
+}
--- /dev/null
+// PR c++/96604
+
+struct A { template<typename T> operator T(); };
+struct X {};
+struct B { friend A::operator X(); };