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: [C++ PATCH] Using declarations should not conflict (fix PR/2294)


On Wednesday, October 29, 2003 9:36 PM [GMT+1=CET],
Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:

>> Two using declarations importing two identical declarations into the
>> current scope should not cause a conflict, but just build an ambiguous
>> overload set (§7.3.3/12 in the draft).

> I think the patch on the right road. But I think it is a half solution.
> We should probably construct an OVERLOAD for any function declaration.
> That simplifies the special cases to handle.

Right. Does this look better? I don't know if you were suggesting to build
OVERLOADs for builtins as well.

Bootstrapped on i686-pc-linux, tested with make check-g++.
OK for mainline?

Giovanni Bajo


2003-10-29  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/2294
        * name-lookup.c (push_overloaded_decl): Always construct an OVERLOAD
        unless the declaration is a built-in.
        (set_namespace_binding): While binding OVERLOADs with only one
declaration,
        we still need to call supplement_binding.

2003-10-29  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/2294
        * g++.dg/lookup/using9.c: New test.


Index: gcc/cp/name-lookup.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.16
diff -c -p -r1.16 name-lookup.c
*** gcc/cp/name-lookup.c        14 Oct 2003 20:34:41 -0000      1.16
--- gcc/cp/name-lookup.c        1 Nov 2003 23:28:12 -0000
*************** push_overloaded_decl (tree decl, int fla
*** 1994,2000 ****
        }
      }

!   if (old || TREE_CODE (decl) == TEMPLATE_DECL)
      {
        if (old && TREE_CODE (old) != OVERLOAD)
        new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
--- 1997,2003 ----
        }
      }

!   if (!DECL_ARTIFICIAL (decl))
      {
        if (old && TREE_CODE (old) != OVERLOAD)
        new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE));
*************** push_overloaded_decl (tree decl, int fla
*** 2004,2010 ****
        OVL_USED (new_binding) = 1;
      }
    else
-     /* NAME is not ambiguous.  */
      new_binding = decl;

    if (doing_global)
*************** set_namespace_binding (tree name, tree s
*** 2862,2868 ****
    if (scope == NULL_TREE)
      scope = global_namespace;
    b = binding_for_name (NAMESPACE_LEVEL (scope), name);
!   if (!b->value || TREE_CODE (val) == OVERLOAD || val == error_mark_node)
      b->value = val;
    else
      supplement_binding (b, val);
--- 2867,2877 ----
    if (scope == NULL_TREE)
      scope = global_namespace;
    b = binding_for_name (NAMESPACE_LEVEL (scope), name);
!   if (!b->value
!       /* If OVL_CHAIN is NULL, it's the first FUNCTION_DECL for this name,
!        and we still need to call supplement_binding.  */
!       || (TREE_CODE (val) == OVERLOAD && OVL_CHAIN (val))
!       || val == error_mark_node)
      b->value = val;
    else
      supplement_binding (b, val);


// { dg-do compile }
// Origin: C++ Standard Draft (7.3.3/12)
// PR c++/2294: using declarations should not conflict, but only cause
//  an ambiguous overload set to be created.

namespace B {
  void f(int);     // { dg-error "note" }
  void f(double);  // { dg-error "note" }
}

namespace C {
  void f(int);     // { dg-error "note" }
  void f(double);  // { dg-error "note" }
  void f(char);    // { dg-error "note" }
}

void h()
{
  using B::f;
  using C::f;
  f('h');
  f(1);         // { dg-error "ambiguous" }
  void f(int);  // { dg-error "previous using declaration" }
}

void m()
{
  void f(int);
  using B::f;   // { dg-error "already declared" }
}



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