Commit f795360d by Jason Merrill Committed by Jason Merrill

PR c++/71227 - specializing hidden friend

	* pt.c (check_explicit_specialization): Give better diagnostic about
	specializing a hidden friend.

From-SVN: r236941
parent 3dc553dd
2016-05-31 Jason Merrill <jason@redhat.com>
PR c++/71227
* pt.c (check_explicit_specialization): Give better diagnostic about
specializing a hidden friend.
2016-05-31 Paolo Carlini <paolo.carlini@oracle.com> 2016-05-31 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/71248 PR c++/71248
......
...@@ -2808,6 +2808,13 @@ check_explicit_specialization (tree declarator, ...@@ -2808,6 +2808,13 @@ check_explicit_specialization (tree declarator,
context. */ context. */
fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname, fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname,
false, true); false, true);
if (fns == error_mark_node)
/* If lookup fails, look for a friend declaration so we can
give a better diagnostic. */
fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname,
/*type*/false, /*complain*/true,
/*hidden*/true);
if (fns == error_mark_node || !is_overloaded_fn (fns)) if (fns == error_mark_node || !is_overloaded_fn (fns))
{ {
error ("%qD is not a template function", dname); error ("%qD is not a template function", dname);
...@@ -2953,6 +2960,15 @@ check_explicit_specialization (tree declarator, ...@@ -2953,6 +2960,15 @@ check_explicit_specialization (tree declarator,
CP_DECL_CONTEXT (tmpl))) CP_DECL_CONTEXT (tmpl)))
error ("%qD is not declared in %qD", error ("%qD is not declared in %qD",
tmpl, current_namespace); tmpl, current_namespace);
else if (TREE_CODE (decl) == FUNCTION_DECL
&& DECL_HIDDEN_FRIEND_P (tmpl))
{
if (pedwarn (DECL_SOURCE_LOCATION (decl), 0,
"friend declaration %qD is not visible to "
"explicit specialization", tmpl))
inform (DECL_SOURCE_LOCATION (tmpl),
"friend declaration here");
}
tree gen_tmpl = most_general_template (tmpl); tree gen_tmpl = most_general_template (tmpl);
......
// PR c++/71227
// { dg-options "" }
class A {
public:
template<typename T>
friend int f(int x, T v) { // { dg-message "declaration" }
return x + v;
}
};
template<>
int f(int x, int v) { // { dg-warning "friend" }
return x + v;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment