return error_mark_node;
}
- decl = do_friend (ctype, unqualified_id, decl,
+ tree scope = ctype ? ctype : in_namespace;
+ decl = do_friend (scope, unqualified_id, decl,
flags, funcdef_flag);
return decl;
}
}
/* Record DECL (a FUNCTION_DECL) as a friend of the
- CURRENT_CLASS_TYPE. If DECL is a member function, CTYPE is the
+ CURRENT_CLASS_TYPE. If DECL is a member function, SCOPE is the
class of which it is a member, as named in the friend declaration.
+ If the friend declaration was explicitly namespace-qualified, SCOPE
+ is that namespace.
DECLARATOR is the name of the friend. FUNCDEF_FLAG is true if the
friend declaration is a definition of the function. FLAGS is as
for grokclass fn. */
tree
-do_friend (tree ctype, tree declarator, tree decl,
+do_friend (tree scope, tree declarator, tree decl,
enum overload_flags flags,
bool funcdef_flag)
{
gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
- gcc_assert (!ctype || MAYBE_CLASS_TYPE_P (ctype));
+
+ tree ctype = NULL_TREE;
+ tree in_namespace = NULL_TREE;
+ if (!scope)
+ ;
+ else if (MAYBE_CLASS_TYPE_P (scope))
+ ctype = scope;
+ else
+ {
+ gcc_checking_assert (TREE_CODE (scope) == NAMESPACE_DECL);
+ in_namespace = scope;
+ }
/* Friend functions are unique, until proved otherwise. */
DECL_UNIQUE_FRIEND_P (decl) = 1;
parameters. Instead, we call pushdecl when the class
is instantiated. */
decl = push_template_decl (decl, /*is_friend=*/true);
- else if (current_function_decl)
+ else if (current_function_decl && !in_namespace)
/* pushdecl will check there's a local decl already. */
decl = pushdecl (decl, /*hiding=*/true);
else