This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] partial fix for PR 13594 (3.4 regression)
On Jan 10, 2004, Eric Botcazou <ebotcazou@libertysurf.fr> wrote:
> FAIL: 23_containers/bitset/invalidation/1.cc (test for excess errors)
> WARNING: 23_containers/bitset/invalidation/1.cc compilation failed to produce
> executable
Here's a patch that fixes this problem. My mistake was to assume that
it was ok to use a single queue for strongly-associated and other
namespaces. Now I see it isn't. We have to first look up the name in
all strongly-associated namespaces and, only if we don't find a
definition in them, should we proceed to other namespaces. The patch
below implements this change, and fixes the regressions my previous
patch had introduced, without new regressions. Ok to install?
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/13594
* name-lookup.c (qualified_lookup_using_namespace): Search
strongly-associated namespaces first, and only then try other
namespaces.
Index: gcc/cp/name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.32
diff -u -p -r1.32 name-lookup.c
--- gcc/cp/name-lookup.c 9 Jan 2004 21:30:31 -0000 1.32
+++ gcc/cp/name-lookup.c 12 Jan 2004 15:09:30 -0000
@@ -3778,6 +3778,7 @@ qualified_lookup_using_namespace (tree n
tree seen = NULL_TREE;
/* ... and a list of namespace yet to see. */
tree todo = NULL_TREE;
+ tree todo_maybe = NULL_TREE;
tree usings;
timevar_push (TV_NAME_LOOKUP);
/* Look through namespace aliases. */
@@ -3785,7 +3786,7 @@ qualified_lookup_using_namespace (tree n
while (scope && result->value != error_mark_node)
{
cxx_binding *binding =
- cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
+ cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
seen = tree_cons (scope, NULL_TREE, seen);
if (binding)
result = ambiguous_decl (name, result, binding, flags);
@@ -3797,15 +3798,35 @@ qualified_lookup_using_namespace (tree n
for (usings = DECL_NAMESPACE_USING (scope); usings;
usings = TREE_CHAIN (usings))
/* If this was a real directive, and we have not seen it. */
- if (!TREE_INDIRECT_USING (usings)
- && ((!result->value && !result->type)
- || is_associated_namespace (scope, TREE_PURPOSE (usings)))
- && !purpose_member (TREE_PURPOSE (usings), seen))
- todo = tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
+ if (!TREE_INDIRECT_USING (usings))
+ {
+ /* Try to avoid queuing the same namespace more than once,
+ the exception being when a namespace was already
+ enqueued for todo_maybe and then a strong using is
+ found for it. We could try to remove it from
+ todo_maybe, but it's probably not worth the effort. */
+ if (is_associated_namespace (scope, TREE_PURPOSE (usings))
+ && !purpose_member (TREE_PURPOSE (usings), seen)
+ && !purpose_member (TREE_PURPOSE (usings), todo))
+ todo = tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
+ else if ((!result->value && !result->type)
+ && !purpose_member (TREE_PURPOSE (usings), seen)
+ && !purpose_member (TREE_PURPOSE (usings), todo)
+ && !purpose_member (TREE_PURPOSE (usings), todo_maybe))
+ todo_maybe = tree_cons (TREE_PURPOSE (usings), NULL_TREE,
+ todo_maybe);
+ }
if (todo)
{
scope = TREE_PURPOSE (todo);
todo = TREE_CHAIN (todo);
+ }
+ else if (todo_maybe
+ && (!result->value && !result->type))
+ {
+ scope = TREE_PURPOSE (todo_maybe);
+ todo = TREE_CHAIN (todo_maybe);
+ todo_maybe = NULL_TREE;
}
else
scope = NULL_TREE; /* If there never was a todo list. */
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/13594
* g++.dg/lookup/strong-using-2.C: New.
Index: gcc/testsuite/g++.dg/lookup/strong-using-2.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/strong-using-2.C
diff -N gcc/testsuite/g++.dg/lookup/strong-using-2.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/strong-using-2.C 12 Jan 2004 15:09:41 -0000
@@ -0,0 +1,25 @@
+// PR c++/13594
+
+// { dg-do compile }
+
+namespace foo_impl {
+ class T; // { dg-error "first declared" "" }
+}
+namespace bar_impl {
+ class T; // { dg-error "also declared" "" }
+}
+namespace foo {
+ using namespace foo_impl __attribute__((strong));
+}
+namespace bar {
+ using namespace bar_impl __attribute__((strong));
+ using namespace foo;
+}
+namespace baz {
+ using namespace foo;
+ using namespace bar;
+}
+
+foo::T *t1;
+bar::T *t2;
+baz::T *t3; // { dg-error "(ambiguous|expected|extra)" "" }
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Happy GNU Year! oliva@{lsd.ic.unicamp.br, gnu.org}
Red Hat GCC Developer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist Professional serial bug killer