This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] partial fix for PR 13594 (3.4 regression)
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, jason at redhat dot com, rsandifo at redhat dot com
- Date: 07 Jan 2004 19:24:19 -0200
- Subject: [PATCH] partial fix for PR 13594 (3.4 regression)
- Organization: GCC Team, Red Hat
This patch fixes a problem that is referenced in bug 13594, but that
is not quite the same as the one reported there. It fixes the bug
that Richard Sandiford mentioned elsewhere (I can't find the bugzilla
number, is there one?), summarized in the included testcase.
The problem was that we didn't honor namespace association when we
found a name in the initial namespace. This patch fixes it.
Unfortunately, contrary to my initial hope, it doesn't fix the problem
in bug report 13594. It actually causes the declarations in the two
separate namespaces to become ambiguous, which sounds like reasonable
behavior to me, but may not be the best choice. More details and
analysis in the PR.
Meanwhile, this patch fixes a different bug, so I thought I'd go ahead
and post it. Built and tested (well, almost completed) on
i686-pc-linux-gnu and frv-elf. Ok to install?
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* name-lookup.c: Consider strong using directives even if we've
already found a binding.
Index: gcc/cp/name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.31
diff -u -p -r1.31 name-lookup.c
--- gcc/cp/name-lookup.c 5 Jan 2004 06:24:44 -0000 1.31
+++ gcc/cp/name-lookup.c 7 Jan 2004 21:18:22 -0000
@@ -1,5 +1,5 @@
/* Definitions for C++ name lookup routines.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
This file is part of GCC.
@@ -3789,14 +3789,19 @@ qualified_lookup_using_namespace (tree n
seen = tree_cons (scope, NULL_TREE, seen);
if (binding)
result = ambiguous_decl (name, result, binding, flags);
- if (!result->value && !result->type)
- /* Consider using directives. */
- 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)
- && !purpose_member (TREE_PURPOSE (usings), seen))
- todo = tree_cons (TREE_PURPOSE (usings), NULL_TREE, todo);
+
+ /* Consider strong using directives always, and non-strong ones
+ if we haven't found a binding yet. ??? Shouldn't we consider
+ non-strong ones if the initial RESULT is non-NULL, but the
+ binding in the given namespace is? */
+ 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 (todo)
{
scope = TREE_PURPOSE (todo);
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* g++.dg/lookup/strong-using-1.C: New.
Index: gcc/testsuite/g++.dg/lookup/strong-using-1.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/strong-using-1.C
diff -N gcc/testsuite/g++.dg/lookup/strong-using-1.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/strong-using-1.C 7 Jan 2004 21:18:32 -0000
@@ -0,0 +1,16 @@
+// PR c++/13594 (secondary)
+
+// { dg-do compile }
+
+namespace foo {
+ template <class T> void swap(T, T);
+}
+namespace fool {
+ using namespace foo __attribute__((strong));
+ template <class T> void swap(T);
+}
+
+int main() {
+ // we used to fail to look up the associated namespace here
+ fool::swap(1, 1);
+}
--
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