aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2004-07-12 01:33:47 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2004-07-12 01:33:47 +0000
commit12cf89fae251c176d37fa37392072a9650f6d4cc (patch)
tree7a29bc1859143741c7e914f78e715d6ffa1d2baf /gcc/cp
parent597073ace8549d2a934a1fe7d9402e1f63e91220 (diff)
downloadgcc-12cf89fae251c176d37fa37392072a9650f6d4cc.zip
gcc-12cf89fae251c176d37fa37392072a9650f6d4cc.tar.gz
gcc-12cf89fae251c176d37fa37392072a9650f6d4cc.tar.bz2
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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/call.c16
-rw-r--r--gcc/cp/name-lookup.c69
-rw-r--r--gcc/cp/name-lookup.h4
-rw-r--r--gcc/cp/parser.c4
5 files changed, 66 insertions, 39 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ea3b13f..e8cef5f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index af8bb88..b4f4dbb 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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. */
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index c47c6be..fb043af 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -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
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index b7e59e8..1b35b46 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -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);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index fc5e8a5..a7fe73d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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;