diff options
Diffstat (limited to 'gcc/cp/friend.c')
-rw-r--r-- | gcc/cp/friend.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index 094501b109a..ffb0baaa600 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -526,11 +526,25 @@ do_friend (tree ctype, tree declarator, tree decl, is instantiated. */ decl = push_template_decl_real (decl, /*is_friend=*/true); else if (current_function_decl) - /* This must be a local class, so pushdecl will be ok, and - insert an unqualified friend into the local scope - (rather than the containing namespace scope, which the - next choice will do). */ - decl = pushdecl_maybe_friend (decl, /*is_friend=*/true); + { + /* This must be a local class. 11.5p11: + + If a friend declaration appears in a local class (9.8) and + the name specified is an unqualified name, a prior + declaration is looked up without considering scopes that + are outside the innermost enclosing non-class scope. For a + friend function declaration, if there is no prior + declaration, the program is ill-formed. */ + tree t = lookup_name_innermost_nonclass_level (DECL_NAME (decl)); + if (t) + decl = pushdecl_maybe_friend (decl, /*is_friend=*/true); + else + { + error ("friend declaration %qD in local class without " + "prior declaration", decl); + return error_mark_node; + } + } else { /* We can't use pushdecl, as we might be in a template |