* call.c (build_operator_new_call): Avoid using push_to_top_level.
(build_new_op): Adjust call to lookup_function_nonclass.
* name-lookup.c (identifier_type_value): Adjust call to
lookup_name_real.
(lookup_name_real): Add block_p parameter.
(lookup_name_nonclass): Adjust call to lookup_name_real.
(lookup_function_nonclass): Likewise.
(lookup_name): Likewise.
* name-lookup.h (lookup_name_real): Change prototype.
(lookup_name_nonclass): Likewise.
* parser.c (cp_parser_lookup_name): Likewise.
From-SVN: r84543
2004-07-11 Mark Mitchell <mark@codesourcery.com>
+ * call.c (build_operator_new_call): Avoid using push_to_top_level.
+ (build_new_op): Adjust call to lookup_function_nonclass.
+ * name-lookup.c (identifier_type_value): Adjust call to
+ lookup_name_real.
+ (lookup_name_real): Add block_p parameter.
+ (lookup_name_nonclass): Adjust call to lookup_name_real.
+ (lookup_function_nonclass): Likewise.
+ (lookup_name): Likewise.
+ * name-lookup.h (lookup_name_real): Change prototype.
+ (lookup_name_nonclass): Likewise.
+ * parser.c (cp_parser_lookup_name): Likewise.
+
* cp-tree.h (saved_scope): Make old_bindings a vector.
(unuse_fields): Remove.
* name-lookup.h (cxx_saved_binding): Define it.
if (args == error_mark_node)
return args;
- /* A global operator new must be looked up only at global scope. */
- push_to_top_level();
- fns = lookup_function_nonclass (fnname, args);
- pop_from_top_level();
+ /* Based on:
+
+ [expr.new]
+
+ If this lookup fails to find the name, or if the allocated type
+ is not a class type, the allocation function's name is looked
+ up in the global scope.
+
+ we disregard block-scope declarations of "operator new". */
+ fns = lookup_function_nonclass (fnname, args, /*block_p=*/false);
/* Figure out what function is being called. */
cand = perform_overload_resolution (fns, args, &candidates, &any_viable_p);
/* Add namespace-scope operators to the list of functions to
consider. */
- add_candidates (lookup_function_nonclass (fnname, arglist),
+ add_candidates (lookup_function_nonclass (fnname, arglist, /*block_p=*/true),
arglist, NULL_TREE, false, NULL_TREE, NULL_TREE,
flags, &candidates);
/* Add class-member operators to the candidate set. */
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, REAL_IDENTIFIER_TYPE_VALUE (id));
/* Have to search for it. It must be on the global level, now.
Ask lookup_name not to return non-types. */
- id = lookup_name_real (id, 2, 1, 0, LOOKUP_COMPLAIN);
+ id = lookup_name_real (id, 2, 1, /*block_p=*/true, 0, LOOKUP_COMPLAIN);
if (id)
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, TREE_TYPE (id));
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
Otherwise we prefer non-TYPE_DECLs.
If NONCLASS is nonzero, we don't look for the NAME in class scope,
- using IDENTIFIER_CLASS_VALUE. */
+ using IDENTIFIER_CLASS_VALUE.
+
+ If BLOCK_P is true, block scopes are examined; otherwise, they are
+ skipped. */
tree
-lookup_name_real (tree name, int prefer_type, int nonclass,
+lookup_name_real (tree name, int prefer_type, int nonclass, bool block_p,
int namespaces_only, int flags)
{
cxx_binding *iter;
if (current_class_type == NULL_TREE)
nonclass = 1;
- for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous)
- {
- tree binding;
-
- if (!LOCAL_BINDING_P (iter) && nonclass)
- /* We're not looking for class-scoped bindings, so keep going. */
- continue;
-
- /* If this is the kind of thing we're looking for, we're done. */
- if (qualify_lookup (iter->value, flags))
- binding = iter->value;
- else if ((flags & LOOKUP_PREFER_TYPES)
- && qualify_lookup (iter->type, flags))
- binding = iter->type;
- else
- binding = NULL_TREE;
-
- if (binding)
- {
- val = binding;
- break;
- }
- }
+ if (block_p || !nonclass)
+ for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous)
+ {
+ tree binding;
+
+ /* Skip entities we don't want. */
+ if (LOCAL_BINDING_P (iter) ? !block_p : nonclass)
+ continue;
+
+ /* If this is the kind of thing we're looking for, we're done. */
+ if (qualify_lookup (iter->value, flags))
+ binding = iter->value;
+ else if ((flags & LOOKUP_PREFER_TYPES)
+ && qualify_lookup (iter->type, flags))
+ binding = iter->type;
+ else
+ binding = NULL_TREE;
+
+ if (binding)
+ {
+ val = binding;
+ break;
+ }
+ }
/* Now lookup in namespace scopes. */
if (!val)
tree
lookup_name_nonclass (tree name)
{
- return lookup_name_real (name, 0, 1, 0, LOOKUP_COMPLAIN);
+ return lookup_name_real (name, 0, 1, /*block_p=*/true, 0, LOOKUP_COMPLAIN);
}
tree
-lookup_function_nonclass (tree name, tree args)
+lookup_function_nonclass (tree name, tree args, bool block_p)
{
- return lookup_arg_dependent (name, lookup_name_nonclass (name), args);
+ return
+ lookup_arg_dependent (name,
+ lookup_name_real (name, 0, 1, block_p, 0,
+ LOOKUP_COMPLAIN),
+ args);
}
tree
lookup_name (tree name, int prefer_type)
{
- return lookup_name_real (name, prefer_type, 0, 0, LOOKUP_COMPLAIN);
+ return lookup_name_real (name, prefer_type, 0, /*block_p=*/true,
+ 0, LOOKUP_COMPLAIN);
}
/* Similar to `lookup_name' but look only in the innermost non-class
extern tree lookup_tag (enum tree_code, tree, cxx_scope *, int);
extern tree lookup_tag_reverse (tree, tree);
extern tree lookup_name (tree, int);
-extern tree lookup_name_real (tree, int, int, int, int);
+extern tree lookup_name_real (tree, int, int, bool, int, int);
extern tree namespace_binding (tree, tree);
extern void set_namespace_binding (tree, tree, tree);
extern tree lookup_namespace_name (tree, tree);
extern tree lookup_qualified_name (tree, tree, bool, bool);
extern tree lookup_name_nonclass (tree);
-extern tree lookup_function_nonclass (tree, tree);
+extern tree lookup_function_nonclass (tree, tree, bool);
extern void push_local_binding (tree, tree, int);
extern int push_class_binding (tree, tree);
extern bool pushdecl_class_level (tree);
/*protect=*/0, is_type);
/* Look it up in the enclosing context, too. */
decl = lookup_name_real (name, is_type, /*nonclass=*/0,
- is_namespace,
+ /*block_p=*/true, is_namespace,
/*flags=*/0);
parser->object_scope = object_type;
parser->qualifying_scope = NULL_TREE;
else
{
decl = lookup_name_real (name, is_type, /*nonclass=*/0,
- is_namespace,
+ /*block_p=*/true, is_namespace,
/*flags=*/0);
parser->qualifying_scope = NULL_TREE;
parser->object_scope = NULL_TREE;