static void push_local_binding (tree, tree, int);
static tree push_overloaded_decl (tree, int);
static bool lookup_using_namespace (tree, cxx_binding *, tree,
- tree, int, tree *);
+ tree, int);
static bool qualified_lookup_using_namespace (tree, tree, cxx_binding *, int);
static tree lookup_type_current_level (tree);
static tree push_using_directive (tree);
}
/* Unscoped lookup of a global: iterate over current namespaces,
- considering using-directives. If SPACESP is non-NULL, store a list
- of the namespaces we've considered in it. */
+ considering using-directives. */
static tree
-unqualified_namespace_lookup (tree name, int flags, tree* spacesp)
+unqualified_namespace_lookup (tree name, int flags)
{
tree initial = current_decl_namespace ();
tree scope = initial;
timevar_push (TV_NAME_LOOKUP);
cxx_binding_clear (&binding);
- if (spacesp)
- *spacesp = NULL_TREE;
for (; !val; scope = CP_DECL_CONTEXT (scope))
{
cxx_binding *b =
cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
- if (spacesp)
- *spacesp = tree_cons (scope, NULL_TREE, *spacesp);
/* Ignore anticipated built-in functions. */
if (b && b->value && DECL_P (b->value)
level->kind != sk_namespace;
level = level->level_chain)
if (!lookup_using_namespace (name, &binding, level->using_directives,
- scope, flags, spacesp))
+ scope, flags))
/* Give up because of error. */
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
{
if (!lookup_using_namespace (name, &binding,
DECL_NAMESPACE_USING (siter),
- scope, flags, spacesp))
+ scope, flags))
/* Give up because of error. */
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
if (siter == scope) break;
flags |= LOOKUP_COMPLAIN;
if (is_type_p)
flags |= LOOKUP_PREFER_TYPES;
- if (qualified_lookup_using_namespace (name, scope, &binding,
- flags))
+ if (qualified_lookup_using_namespace (name, scope, &binding, flags))
return select_decl (&binding, flags);
}
else if (is_aggr_type (scope, complain))
static bool
lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope,
- int flags, tree *spacesp)
+ int flags)
{
tree iter;
timevar_push (TV_NAME_LOOKUP);
tree used = ORIGINAL_NAMESPACE (TREE_PURPOSE (iter));
cxx_binding *val1 =
cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (used), name);
- if (spacesp)
- *spacesp = tree_cons (used, NULL_TREE, *spacesp);
/* Resolve ambiguities. */
if (val1)
val = ambiguous_decl (name, val, val1, flags);
/* Now lookup in namespace scopes. */
if (!val)
{
- tree t = unqualified_namespace_lookup (name, flags, 0);
+ tree t = unqualified_namespace_lookup (name, flags);
if (t)
val = t;
}
k.functions = fns;
k.classes = NULL_TREE;
- /* Note that we've already looked at some namespaces during normal
- unqualified lookup, unless we found a decl in function scope. */
+ /* We've already looked at some namespaces during normal unqualified
+ lookup -- but we don't know exactly which ones. If the functions
+ we found were brought into the current namespace via a using
+ declaration, we have not really checked the namespace from which
+ they came. Therefore, we check all namespaces here -- unless the
+ function we have is from the current namespace. */
if (fns)
fn = OVL_CURRENT (fns);
- if (fn && TREE_CODE (fn) == FUNCTION_DECL && DECL_LOCAL_FUNCTION_P (fn))
+ if (fn && TREE_CODE (fn) == FUNCTION_DECL
+ && CP_DECL_CONTEXT (fn) != current_decl_namespace ())
k.namespaces = NULL_TREE;
else
- unqualified_namespace_lookup (name, 0, &k.namespaces);
+ /* Setting NAMESPACES is purely an optimization; it prevents
+ adding functions which are already in FNS. Adding them would
+ be safe -- "joust" will eliminate the duplicates -- but
+ wasteful. */
+ k.namespaces = build_tree_list (current_decl_namespace (), NULL_TREE);
arg_assoc_args (&k, args);
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, k.functions);