This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: swap does not compile


Yes, this patch looks OK, thanks.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
----- Original Message ----- 
From: "Alexandre Oliva" <aoliva@redhat.com>
To: "Mark Mitchell" <mark@codesourcery.com>; <gcc-patches@gcc.gnu.org>
Cc: "Jonathan Wakely" <cow@compsoc.man.ac.uk>; <bkoz@redhat.com>;
<larsbj@gullik.net>; <libstdc++@gcc.gnu.org>; <jason@redhat.com>;
<gcc@gcc.gnu.org>
Sent: Tuesday, January 13, 2004 5:58 AM
Subject: Re: swap does not compile


> On Jan 12, 2004, Mark Mitchell <mark@codesourcery.com> wrote:
>
> > On Mon, 2004-01-12 at 17:01, Alexandre Oliva wrote:
> >> On Jan 12, 2004, Alexandre Oliva <aoliva@redhat.com> wrote:
>
> > This is probably OK -- but it would be more reliable to just get the
> > return value from cp_parser_nested_name_specifier_{,opt}.  They will
> > return the qualifying scope for you. :-)
>
> Unless it's the global namespace, as I found out :-)
>
> > With that change, the patch is OK.
>
> Here's the patch I'll check in as soon as my other patch (for PR
> c++/13594) is in, since I've only tested this patch atop of that, and
> since before that one there were libstdc++ regressions, it's probably
> not a good idea to test without it anyway.
>
>


----------------------------------------------------------------------------
----


> 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 13:48:10 -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 13:48:10 -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.152
> diff -u -p -r1.152 parser.c
> --- gcc/cp/parser.c 13 Jan 2004 00:44:50 -0000 1.152
> +++ gcc/cp/parser.c 13 Jan 2004 13:48:19 -0000
> @@ -9392,6 +9392,7 @@ cp_parser_using_declaration (cp_parser*
>    tree decl;
>    tree identifier;
>    tree scope;
> +  tree qscope;
>
>    /* Look for the `using' keyword.  */
>    cp_parser_require_keyword (parser, RID_USING, "`using'");
> @@ -9416,18 +9417,20 @@ cp_parser_using_declaration (cp_parser*
>    /* If we saw `typename', or didn't see `::', then there must be a
>       nested-name-specifier present.  */
>    if (typename_p || !global_scope_p)
> -    cp_parser_nested_name_specifier (parser, typename_p,
> -      /*check_dependency_p=*/true,
> -      /*type_p=*/false,
> -      /*is_declaration=*/true);
> +    qscope = cp_parser_nested_name_specifier (parser, typename_p,
> +       /*check_dependency_p=*/true,
> +       /*type_p=*/false,
> +       /*is_declaration=*/true);
>    /* Otherwise, we could be in either of the two productions.  In that
>       case, treat the nested-name-specifier as optional.  */
>    else
> -    cp_parser_nested_name_specifier_opt (parser,
> - /*typename_keyword_p=*/false,
> - /*check_dependency_p=*/true,
> - /*type_p=*/false,
> - /*is_declaration=*/true);
> +    qscope = cp_parser_nested_name_specifier_opt (parser,
> +   /*typename_keyword_p=*/false,
> +   /*check_dependency_p=*/true,
> +   /*type_p=*/false,
> +   /*is_declaration=*/true);
> +  if (!qscope)
> +    qscope = global_namespace;
>
>    /* Parse the unqualified-id.  */
>    identifier = cp_parser_unqualified_id (parser,
> @@ -9463,9 +9466,9 @@ 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, qscope, identifier);
>     else
> -     do_toplevel_using_decl (decl);
> +     do_toplevel_using_decl (decl, qscope, identifier);
>   }
>      }
>
> Index: gcc/cp/pt.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
> retrieving revision 1.813
> diff -u -p -r1.813 pt.c
> --- gcc/cp/pt.c 13 Jan 2004 01:02:27 -0000 1.813
> +++ gcc/cp/pt.c 13 Jan 2004 13:48:27 -0000
> @@ -7695,7 +7695,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
13:48:39 -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 13:48:39 -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
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]