aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/friend.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2008-01-22 14:50:37 -0500
committerJason Merrill <jason@gcc.gnu.org>2008-01-22 14:50:37 -0500
commit7655e009c8f506454a5cc16bace7282b67513c00 (patch)
treed611d9e565111bcaa97ac42d5cbee302da3e523c /gcc/cp/friend.c
parentb5ca4fd2f6927b6c2cc9ca3f315980b9cbf45605 (diff)
downloadgcc-7655e009c8f506454a5cc16bace7282b67513c00.zip
gcc-7655e009c8f506454a5cc16bace7282b67513c00.tar.gz
gcc-7655e009c8f506454a5cc16bace7282b67513c00.tar.bz2
re PR c++/34912 (ICE with friend in local class)
PR c++/34912 * friend.c (do_friend): Check for prior declaration of a friend function of a local class. * name-lookup.c (lookup_name_innermost_nonclass_level): No longer static. * name-lookup.h: Declare it. From-SVN: r131740
Diffstat (limited to 'gcc/cp/friend.c')
-rw-r--r--gcc/cp/friend.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c
index 094501b1..ffb0baa 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