From 7128d6ab21878794ac2107961338fc8621536a40 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 16 Feb 2016 14:01:49 -0500 Subject: [PATCH] re PR c++/69657 (abs() not inlined after including math.h) PR c++/69657 * name-lookup.c (lookup_qualified_name): Add find_hidden parm. (set_decl_namespace): Pass it. Complain about finding a hidden friend. * name-lookup.h: Adjust. From-SVN: r233470 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/name-lookup.c | 15 +++++++++++++-- gcc/cp/name-lookup.h | 2 +- gcc/testsuite/g++.dg/lookup/friend17.C | 9 +++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/friend17.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 743e059956a..90c76ffcd4e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-02-16 Jason Merrill + + PR c++/69657 + * name-lookup.c (lookup_qualified_name): Add find_hidden parm. + (set_decl_namespace): Pass it. Complain about finding a hidden friend. + * name-lookup.h: Adjust. + 2016-02-16 James Norris * parser.c (cp_parser_oacc_data_clause_deviceptr): Remove checking. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index b5961e573f3..b73f3f7345f 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3502,7 +3502,8 @@ set_decl_namespace (tree decl, tree scope, bool friendp) } /* See whether this has been declared in the namespace. */ - old = lookup_qualified_name (scope, DECL_NAME (decl), false, true); + old = lookup_qualified_name (scope, DECL_NAME (decl), /*type*/false, + /*complain*/true, /*hidden*/true); if (old == error_mark_node) /* No old declaration at all. */ goto complain; @@ -3565,6 +3566,12 @@ set_decl_namespace (tree decl, tree scope, bool friendp) { if (!is_associated_namespace (scope, CP_DECL_CONTEXT (found))) goto complain; + if (DECL_HIDDEN_FRIEND_P (found)) + { + pedwarn (DECL_SOURCE_LOCATION (decl), 0, + "%qD has not been declared within %D", decl, scope); + inform (DECL_SOURCE_LOCATION (found), "only here as a friend"); + } DECL_CONTEXT (decl) = DECL_CONTEXT (found); return; } @@ -4509,11 +4516,15 @@ unqualified_namespace_lookup (tree name, int flags) neither a class-type nor a namespace a diagnostic is issued. */ tree -lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain) +lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain, + bool find_hidden) { int flags = 0; tree t = NULL_TREE; + if (find_hidden) + flags |= LOOKUP_HIDDEN; + if (TREE_CODE (scope) == NAMESPACE_DECL) { struct scope_binding binding = EMPTY_SCOPE_BINDING; diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index bce12bbb26b..7e39b6c92e0 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -327,7 +327,7 @@ extern tree namespace_binding (tree, tree); extern void set_namespace_binding (tree, tree, tree); extern bool hidden_name_p (tree); extern tree remove_hidden_names (tree); -extern tree lookup_qualified_name (tree, tree, bool, bool); +extern tree lookup_qualified_name (tree, tree, bool, bool, /*hidden*/bool = false); extern tree lookup_name_nonclass (tree); extern tree lookup_name_innermost_nonclass_level (tree); extern bool is_local_extern (tree); diff --git a/gcc/testsuite/g++.dg/lookup/friend17.C b/gcc/testsuite/g++.dg/lookup/friend17.C new file mode 100644 index 00000000000..46b6be55831 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend17.C @@ -0,0 +1,9 @@ +// PR c++/69657 +// { dg-options "-Wpedantic" } + +namespace N { + struct A { + friend void f(A); + }; +} +void N::f(A) { } // { dg-warning "declared" } -- 2.30.2