call.c (build_operator_new_call): Avoid using push_to_top_level.

* 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
This commit is contained in:
Mark Mitchell 2004-07-12 01:33:47 +00:00 committed by Mark Mitchell
parent 597073ace8
commit 12cf89fae2
5 changed files with 66 additions and 39 deletions

View File

@ -1,5 +1,17 @@
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.

View File

@ -2812,10 +2812,16 @@ build_operator_new_call (tree fnname, tree args, tree *size, tree *cookie_size)
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);
@ -3636,7 +3642,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
/* 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. */

View File

@ -1745,7 +1745,7 @@ identifier_type_value (tree id)
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);
@ -3998,10 +3998,13 @@ qualified_lookup_using_namespace (tree name, tree scope,
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;
@ -4044,29 +4047,30 @@ lookup_name_real (tree name, int prefer_type, int nonclass,
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)
@ -4089,19 +4093,24 @@ lookup_name_real (tree name, int prefer_type, int nonclass,
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

View File

@ -304,13 +304,13 @@ extern tree pushdecl_with_scope (tree, cxx_scope *);
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);

View File

@ -14245,7 +14245,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
/*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;
@ -14255,7 +14255,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
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;