This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: swap does not compile
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>, bkoz at redhat dot com
- Cc: Lars Gullik BjÃnnes <larsbj at gullik dot net>, libstdc++ at gcc dot gnu dot org, mark at codesourcery dot com, jason at redhat dot com, gcc at gcc dot gnu dot org
- Date: 12 Jan 2004 23:01:14 -0200
- Subject: Re: swap does not compile
- Organization: GCC Team, Red Hat
- References: <m3llodldx6.fsf@tyfon.gullik.net><m365fh7bwp.fsf@uniton.integrable-solutions.net><m3d69plcvn.fsf@tyfon.gullik.net><20040112123859.GA79416@compsoc.man.ac.uk><or7jzx2lfu.fsf@free.redhat.lsd.ic.unicamp.br>
On Jan 12, 2004, Alexandre Oliva <aoliva@redhat.com> wrote:
> Not really. cp_parser_name_lookup_name_simple() can return to
> cp_parser_using_declaration() an overload involving functions in more
> than one namespace, but then do_{local,toplevel}_using_decl() call
> validate_nonmember_using_decl() that extracts the scope from the first
> overload only.
This patch is an attempt to fix the bug. The one bit I'm not sure of
is whether parser->qualifying_scope is guaranteed to still hold the
correct value at the point I use it. Would someone more familiar with
the new parser please have a double check?
g++ testsuite completed without regressions, libstdc++ testsuite
pretty much completed similarly. Ok to install?
Ben, I'll leave the test for the right specialization of swap for
vectors for you (PR 13658), if you don't mind. I've no idea of how to
test for this kind of stuff in the libstdc++ testsuite.
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/13659
* name-lookup.c (validate_nonmember_using_decl): Take scope and
name by value, instead of computing them.
(do_local_using_decl, do_toplevel_using_decl): Add scope and name
arguments. Pass them to validate_nonmember_using_decl.
* name-lookup.h (do_local_using_decl): Adjust.
(do_toplevel_using_decl): Likewise.
* parser.c (cp_parser_using_declaration): Likewise.
* pt.c (tsubst_expr): Likewise.
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 13 Jan 2004 00:49:45 -0000
@@ -2071,17 +2071,13 @@ push_overloaded_decl (tree decl, int fla
being used, and the USING_DECL, or NULL_TREE on failure. */
static tree
-validate_nonmember_using_decl (tree decl, tree *scope, tree *name)
+validate_nonmember_using_decl (tree decl, tree scope, tree name)
{
- *scope = global_namespace;
- *name = NULL_TREE;
-
if (TREE_CODE (decl) == TEMPLATE_ID_EXPR)
{
- *name = TREE_OPERAND (decl, 0);
/* 7.3.3/5
A using-declaration shall not name a template-id. */
- error ("a using-declaration cannot specify a template-id. Try `using %D'", *name);
+ error ("a using-declaration cannot specify a template-id. Try `using %D'", name);
return NULL_TREE;
}
@@ -2104,25 +2100,17 @@ validate_nonmember_using_decl (tree decl
my_friendly_assert (DECL_P (decl), 20020908);
- if (TREE_CODE (decl) == CONST_DECL)
- /* Enumeration constants to not have DECL_CONTEXT set. */
- *scope = TYPE_CONTEXT (TREE_TYPE (decl));
- else
- *scope = DECL_CONTEXT (decl);
- if (!*scope)
- *scope = global_namespace;
-
/* [namespace.udecl]
A using-declaration for a class member shall be a
member-declaration. */
- if (TYPE_P (*scope))
+ if (TYPE_P (scope))
{
- error ("`%T' is not a namespace", *scope);
+ error ("`%T' is not a namespace", scope);
return NULL_TREE;
}
- *name = DECL_NAME (decl);
+
/* Make a USING_DECL. */
- return push_using_decl (*scope, *name);
+ return push_using_decl (scope, name);
}
/* Process local and global using-declarations. */
@@ -2235,12 +2223,11 @@ do_nonmember_using_decl (tree scope, tre
/* Process a using-declaration at function scope. */
void
-do_local_using_decl (tree decl)
+do_local_using_decl (tree decl, tree scope, tree name)
{
- tree scope, name;
tree oldval, oldtype, newval, newtype;
- decl = validate_nonmember_using_decl (decl, &scope, &name);
+ decl = validate_nonmember_using_decl (decl, scope, name);
if (decl == NULL_TREE)
return;
@@ -3248,13 +3235,12 @@ add_using_namespace (tree user, tree use
/* Process a using-declaration not appearing in class or local scope. */
void
-do_toplevel_using_decl (tree decl)
+do_toplevel_using_decl (tree decl, tree scope, tree name)
{
- tree scope, name;
tree oldval, oldtype, newval, newtype;
cxx_binding *binding;
- decl = validate_nonmember_using_decl (decl, &scope, &name);
+ decl = validate_nonmember_using_decl (decl, scope, name);
if (decl == NULL_TREE)
return;
Index: gcc/cp/name-lookup.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.h,v
retrieving revision 1.13
diff -u -p -r1.13 name-lookup.h
--- gcc/cp/name-lookup.h 2 Dec 2003 10:11:24 -0000 1.13
+++ gcc/cp/name-lookup.h 13 Jan 2004 00:49:45 -0000
@@ -301,8 +301,8 @@ extern tree current_decl_namespace (void
extern void push_decl_namespace (tree);
extern void pop_decl_namespace (void);
extern void do_namespace_alias (tree, tree);
-extern void do_toplevel_using_decl (tree);
-extern void do_local_using_decl (tree);
+extern void do_toplevel_using_decl (tree, tree, tree);
+extern void do_local_using_decl (tree, tree, tree);
extern tree do_class_using_decl (tree);
extern void do_using_directive (tree);
extern tree lookup_arg_dependent (tree, tree, tree);
Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.149
diff -u -p -r1.149 parser.c
--- gcc/cp/parser.c 11 Jan 2004 20:33:35 -0000 1.149
+++ gcc/cp/parser.c 13 Jan 2004 00:49:54 -0000
@@ -9458,9 +9458,11 @@ cp_parser_using_declaration (cp_parser*
if (decl == error_mark_node)
cp_parser_name_lookup_error (parser, identifier, decl, NULL);
else if (scope)
- do_local_using_decl (decl);
+ do_local_using_decl (decl, parser->qualifying_scope,
+ identifier);
else
- do_toplevel_using_decl (decl);
+ do_toplevel_using_decl (decl, parser->qualifying_scope,
+ identifier);
}
}
Index: gcc/cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.811
diff -u -p -r1.811 pt.c
--- gcc/cp/pt.c 12 Jan 2004 13:18:13 -0000 1.811
+++ gcc/cp/pt.c 13 Jan 2004 00:50:02 -0000
@@ -7712,7 +7712,7 @@ tsubst_expr (tree t, tree args, tsubst_f
if (decl == error_mark_node)
qualified_name_lookup_error (scope, name);
else
- do_local_using_decl (decl);
+ do_local_using_decl (decl, scope, name);
}
else
{
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c++/13659
* g++.dg/lookup/strong-using-3.C: New.
* g++.dg/lookup/using-10.C: New.
Index: gcc/testsuite/g++.dg/lookup/strong-using-3.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/strong-using-3.C
diff -N gcc/testsuite/g++.dg/lookup/strong-using-3.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/strong-using-3.C 13 Jan 2004 00:50:15 -0000
@@ -0,0 +1,18 @@
+// PR c++/13659
+
+// { dg-do compile }
+
+namespace foo {
+ template <class T> void f(T, T);
+}
+namespace bar {
+ using namespace foo __attribute__((strong));
+ template <class T> void f(T);
+}
+
+int main() {
+ // Make sure both declarations are brought in.
+ using bar::f;
+ f(1);
+ f(1, 1);
+}
Index: gcc/testsuite/g++.dg/lookup/using-10.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/using-10.C
diff -N gcc/testsuite/g++.dg/lookup/using-10.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/using-10.C 13 Jan 2004 00:50:15 -0000
@@ -0,0 +1,22 @@
+// PR c++/13659
+
+// { dg-do compile }
+
+namespace foo1 {
+ template <class T> void f(T);
+}
+namespace foo2 {
+ template <class T> void f(T, T);
+}
+namespace foo {
+ using namespace foo1;
+ using namespace foo2;
+}
+
+// Make sure we bring in both declarations.
+using foo::f;
+
+int main() {
+ f(1);
+ f(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