diff options
Diffstat (limited to 'gcc/cp/name-lookup.c')
-rw-r--r-- | gcc/cp/name-lookup.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index e5a34003702..9117e0b30eb 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3071,6 +3071,7 @@ do_pushdecl (tree decl, bool is_friend) old = OVL_CHAIN (old); check_template_shadow (decl); + bool visible_injection = false; if (DECL_DECLARES_FUNCTION_P (decl)) { @@ -3079,14 +3080,20 @@ do_pushdecl (tree decl, bool is_friend) if (is_friend) { if (level->kind != sk_namespace) - /* In a local class, a friend function declaration must - find a matching decl in the innermost non-class scope. - [class.friend/11] */ - error ("friend declaration %qD in local class without " - "prior local declaration", decl); - else if (!flag_friend_injection) + { + /* In a local class, a friend function declaration must + find a matching decl in the innermost non-class scope. + [class.friend/11] */ + error ("friend declaration %qD in local class without " + "prior local declaration", decl); + /* Don't attempt to push it. */ + return error_mark_node; + } + if (!flag_friend_injection) /* Hide it from ordinary lookup. */ DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true; + else + visible_injection = true; } } @@ -3138,6 +3145,9 @@ do_pushdecl (tree decl, bool is_friend) } else if (VAR_P (decl)) maybe_register_incomplete_var (decl); + else if (visible_injection) + warning (0, "injected friend %qD is visible" + " due to %<-ffriend-injection%>", decl); if ((VAR_P (decl) || TREE_CODE (decl) == FUNCTION_DECL) && DECL_EXTERN_C_P (decl)) |