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.


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" }
}
