From c0edbb32c15b1c5c2145294641e1dec688d23adc Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 24 May 2017 15:56:06 +0000 Subject: [PATCH] cp-tree.h (ovl_skip_hidden): Declare. * cp-tree.h (ovl_skip_hidden): Declare. * tree.c (ovl_skip_hidden): New. * name-lookup.c (arg_assoc_namespace): Call ovl_skip_hidden. (lookup_arg_dependent_1): Likewise. (ambiguous_decl): Use DECL_HIDDEN_P, ovl_skip_hidden. (hidden_name_p, remove_hidden_names): Delete. (lookup_name_real_1): Do not strip hidden names. * name-lookup.h (hidden_name_p, remove_hidden_names): Delete. From-SVN: r248423 --- gcc/cp/ChangeLog | 9 ++++++ gcc/cp/cp-tree.h | 1 + gcc/cp/name-lookup.c | 71 ++++---------------------------------------- gcc/cp/name-lookup.h | 2 -- gcc/cp/tree.c | 21 +++++++++++++ 5 files changed, 36 insertions(+), 68 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 16e30fa43d7..27716d3d382 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2017-05-24 Nathan Sidwell + * cp-tree.h (ovl_skip_hidden): Declare. + * tree.c (ovl_skip_hidden): New. + * name-lookup.c (arg_assoc_namespace): Call ovl_skip_hidden. + (lookup_arg_dependent_1): Likewise. + (ambiguous_decl): Use DECL_HIDDEN_P, ovl_skip_hidden. + (hidden_name_p, remove_hidden_names): Delete. + (lookup_name_real_1): Do not strip hidden names. + * name-lookup.h (hidden_name_p, remove_hidden_names): Delete. + * cp-tree.h (OVL_HIDDEN_P): New. (ovl_iterator::hidden_p, ovl_iterator::reveal_node): New. (ovl_iterator::reveal_node): Declare. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 7f1c632da1d..d52a784f2f7 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6852,6 +6852,7 @@ extern tree ovl_make (tree fn, tree next = NULL_TREE); extern tree ovl_insert (tree fn, tree maybe_ovl, bool using_p = false); +extern tree ovl_skip_hidden (tree); extern tree lookup_add (tree fns, tree lookup); extern void lookup_keep (tree lookup, bool keep); extern int is_overloaded_fn (tree); diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 57d85a5a017..88fd7edcb21 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -275,14 +275,10 @@ arg_assoc_namespace (struct arg_lookup *k, tree scope) if (!value) return false; + value = ovl_skip_hidden (value); + for (; value; value = OVL_NEXT (value)) { - /* We don't want to find arbitrary hidden functions via argument - dependent lookup. We only want to find friends of associated - classes, which we'll do via arg_assoc_class. */ - if (hidden_name_p (OVL_CURRENT (value))) - continue; - if (add_function (k, OVL_CURRENT (value))) return true; } @@ -630,7 +626,7 @@ lookup_arg_dependent_1 (tree name, tree fns, vec *args) /* Remove any hidden friend functions from the list of functions found so far. They will be added back by arg_assoc_class as appropriate. */ - fns = remove_hidden_names (fns); + fns = ovl_skip_hidden (fns); k.name = name; k.args = args; @@ -4347,7 +4343,7 @@ ambiguous_decl (struct scope_binding *old, cxx_binding *new_binding, int flags) /* Copy the type. */ type = new_binding->type; if (LOOKUP_NAMESPACES_ONLY (flags) - || (type && hidden_name_p (type) && !(flags & LOOKUP_HIDDEN))) + || (type && !(flags & LOOKUP_HIDDEN) && DECL_HIDDEN_P (type))) type = NULL_TREE; /* Copy the value. */ @@ -4355,7 +4351,7 @@ ambiguous_decl (struct scope_binding *old, cxx_binding *new_binding, int flags) if (val) { if (!(flags & LOOKUP_HIDDEN)) - val = remove_hidden_names (val); + val = ovl_skip_hidden (val); if (val) switch (TREE_CODE (val)) { @@ -4465,59 +4461,6 @@ qualify_lookup (tree val, int flags) return true; } -/* Given a lookup that returned VAL, decide if we want to ignore it or - not based on DECL_ANTICIPATED. */ - -bool -hidden_name_p (tree val) -{ - if (DECL_P (val) - && DECL_LANG_SPECIFIC (val) - && TYPE_FUNCTION_OR_TEMPLATE_DECL_P (val) - && DECL_ANTICIPATED (val)) - return true; - if (TREE_CODE (val) == OVERLOAD) - { - for (tree o = val; o; o = OVL_CHAIN (o)) - if (!hidden_name_p (OVL_FUNCTION (o))) - return false; - return true; - } - return false; -} - -/* Remove any hidden declarations from a possibly overloaded set - of functions. */ - -tree -remove_hidden_names (tree fns) -{ - if (!fns) - return fns; - - if (DECL_P (fns) && hidden_name_p (fns)) - fns = NULL_TREE; - else if (TREE_CODE (fns) == OVERLOAD) - { - tree o; - - for (o = fns; o; o = OVL_NEXT (o)) - if (hidden_name_p (OVL_CURRENT (o))) - break; - if (o) - { - tree n = NULL_TREE; - - for (o = fns; o; o = OVL_NEXT (o)) - if (!hidden_name_p (OVL_CURRENT (o))) - n = lookup_add (OVL_CURRENT (o), n); - fns = n; - } - } - - return fns; -} - /* Suggest alternatives for NAME, an IDENTIFIER_NODE for which name lookup failed. Search through all available namespaces and print out possible candidates. If no exact matches are found, and @@ -5337,10 +5280,6 @@ lookup_name_real_1 (tree name, int prefer_type, int nonclass, bool block_p, if (!val) val = unqualified_namespace_lookup (name, flags); - /* Anticipated built-ins and friends aren't found by normal lookup. */ - if (val && !(flags & LOOKUP_HIDDEN)) - val = remove_hidden_names (val); - /* If we have a single function from a using decl, pull it out. */ if (val && TREE_CODE (val) == OVERLOAD && !really_overloaded_fn (val)) val = OVL_FUNCTION (val); diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 85a5b69f962..f0df1c9c30d 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -308,8 +308,6 @@ extern tree lookup_name_real (tree, int, int, bool, int, int); extern tree lookup_type_scope (tree, tag_scope); extern tree get_namespace_binding (tree ns, tree id); extern void set_global_binding (tree id, tree val); -extern bool hidden_name_p (tree); -extern tree remove_hidden_names (tree); extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false); extern tree lookup_name_nonclass (tree); extern tree lookup_name_innermost_nonclass_level (tree); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 5ae9601aaef..29e3256c871 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2204,6 +2204,27 @@ ovl_insert (tree fn, tree maybe_ovl, bool using_p) return result; } +/* Skip any hidden names at the beginning of OVL. */ + +tree +ovl_skip_hidden (tree ovl) +{ + for (; + ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl); + ovl = OVL_CHAIN (ovl)) + gcc_checking_assert (DECL_HIDDEN_P (OVL_FUNCTION (ovl))); + + if (ovl && TREE_CODE (ovl) != OVERLOAD && DECL_HIDDEN_P (ovl)) + { + /* Any hidden functions should have been wrapped in an + overload, but injected friend classes will not. */ + gcc_checking_assert (!DECL_DECLARES_FUNCTION_P (ovl)); + ovl = NULL_TREE; + } + + return ovl; +} + /* NODE is an OVL_HIDDEN_P node which is now revealed. */ tree -- 2.30.2