Commit 12cf89fa by Mark Mitchell Committed by Mark Mitchell

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
parent 597073ac
2004-07-11 Mark Mitchell <mark@codesourcery.com> 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. * cp-tree.h (saved_scope): Make old_bindings a vector.
(unuse_fields): Remove. (unuse_fields): Remove.
* name-lookup.h (cxx_saved_binding): Define it. * name-lookup.h (cxx_saved_binding): Define it.
......
...@@ -2812,10 +2812,16 @@ build_operator_new_call (tree fnname, tree args, tree *size, tree *cookie_size) ...@@ -2812,10 +2812,16 @@ build_operator_new_call (tree fnname, tree args, tree *size, tree *cookie_size)
if (args == error_mark_node) if (args == error_mark_node)
return args; return args;
/* A global operator new must be looked up only at global scope. */ /* Based on:
push_to_top_level();
fns = lookup_function_nonclass (fnname, args); [expr.new]
pop_from_top_level();
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. */ /* Figure out what function is being called. */
cand = perform_overload_resolution (fns, args, &candidates, &any_viable_p); 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, ...@@ -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 /* Add namespace-scope operators to the list of functions to
consider. */ 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, arglist, NULL_TREE, false, NULL_TREE, NULL_TREE,
flags, &candidates); flags, &candidates);
/* Add class-member operators to the candidate set. */ /* Add class-member operators to the candidate set. */
......
...@@ -1745,7 +1745,7 @@ identifier_type_value (tree id) ...@@ -1745,7 +1745,7 @@ identifier_type_value (tree id)
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, REAL_IDENTIFIER_TYPE_VALUE (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. /* Have to search for it. It must be on the global level, now.
Ask lookup_name not to return non-types. */ 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) if (id)
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, TREE_TYPE (id)); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, TREE_TYPE (id));
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
...@@ -3998,10 +3998,13 @@ qualified_lookup_using_namespace (tree name, tree scope, ...@@ -3998,10 +3998,13 @@ qualified_lookup_using_namespace (tree name, tree scope,
Otherwise we prefer non-TYPE_DECLs. Otherwise we prefer non-TYPE_DECLs.
If NONCLASS is nonzero, we don't look for the NAME in class scope, 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 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) int namespaces_only, int flags)
{ {
cxx_binding *iter; cxx_binding *iter;
...@@ -4044,29 +4047,30 @@ lookup_name_real (tree name, int prefer_type, int nonclass, ...@@ -4044,29 +4047,30 @@ lookup_name_real (tree name, int prefer_type, int nonclass,
if (current_class_type == NULL_TREE) if (current_class_type == NULL_TREE)
nonclass = 1; nonclass = 1;
for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous) if (block_p || !nonclass)
{ for (iter = IDENTIFIER_BINDING (name); iter; iter = iter->previous)
tree binding; {
tree binding;
if (!LOCAL_BINDING_P (iter) && nonclass)
/* We're not looking for class-scoped bindings, so keep going. */ /* Skip entities we don't want. */
continue; 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)) /* If this is the kind of thing we're looking for, we're done. */
binding = iter->value; if (qualify_lookup (iter->value, flags))
else if ((flags & LOOKUP_PREFER_TYPES) binding = iter->value;
&& qualify_lookup (iter->type, flags)) else if ((flags & LOOKUP_PREFER_TYPES)
binding = iter->type; && qualify_lookup (iter->type, flags))
else binding = iter->type;
binding = NULL_TREE; else
binding = NULL_TREE;
if (binding)
{ if (binding)
val = binding; {
break; val = binding;
} break;
} }
}
/* Now lookup in namespace scopes. */ /* Now lookup in namespace scopes. */
if (!val) if (!val)
...@@ -4089,19 +4093,24 @@ lookup_name_real (tree name, int prefer_type, int nonclass, ...@@ -4089,19 +4093,24 @@ lookup_name_real (tree name, int prefer_type, int nonclass,
tree tree
lookup_name_nonclass (tree name) 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 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 tree
lookup_name (tree name, int prefer_type) 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 /* Similar to `lookup_name' but look only in the innermost non-class
......
...@@ -304,13 +304,13 @@ extern tree pushdecl_with_scope (tree, cxx_scope *); ...@@ -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 (enum tree_code, tree, cxx_scope *, int);
extern tree lookup_tag_reverse (tree, tree); extern tree lookup_tag_reverse (tree, tree);
extern tree lookup_name (tree, int); 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 tree namespace_binding (tree, tree);
extern void set_namespace_binding (tree, tree, tree); extern void set_namespace_binding (tree, tree, tree);
extern tree lookup_namespace_name (tree, tree); extern tree lookup_namespace_name (tree, tree);
extern tree lookup_qualified_name (tree, tree, bool, bool); extern tree lookup_qualified_name (tree, tree, bool, bool);
extern tree lookup_name_nonclass (tree); 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 void push_local_binding (tree, tree, int);
extern int push_class_binding (tree, tree); extern int push_class_binding (tree, tree);
extern bool pushdecl_class_level (tree); extern bool pushdecl_class_level (tree);
......
...@@ -14245,7 +14245,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name, ...@@ -14245,7 +14245,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
/*protect=*/0, is_type); /*protect=*/0, is_type);
/* Look it up in the enclosing context, too. */ /* Look it up in the enclosing context, too. */
decl = lookup_name_real (name, is_type, /*nonclass=*/0, decl = lookup_name_real (name, is_type, /*nonclass=*/0,
is_namespace, /*block_p=*/true, is_namespace,
/*flags=*/0); /*flags=*/0);
parser->object_scope = object_type; parser->object_scope = object_type;
parser->qualifying_scope = NULL_TREE; parser->qualifying_scope = NULL_TREE;
...@@ -14255,7 +14255,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name, ...@@ -14255,7 +14255,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
else else
{ {
decl = lookup_name_real (name, is_type, /*nonclass=*/0, decl = lookup_name_real (name, is_type, /*nonclass=*/0,
is_namespace, /*block_p=*/true, is_namespace,
/*flags=*/0); /*flags=*/0);
parser->qualifying_scope = NULL_TREE; parser->qualifying_scope = NULL_TREE;
parser->object_scope = NULL_TREE; parser->object_scope = NULL_TREE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment