Don't push OverloadedFunctionDecls onto the chain of declarations
attached to an identifier. Instead, all overloaded functions will be
pushed into scope, and we'll synthesize an OverloadedFunctionDecl on
the fly when we need it. 



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61386 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index eb2e647..9ffa6ae 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -515,26 +515,15 @@
   DeclContext *GlobalCtx = Context.getTranslationUnitDecl();
 
   // Check if this function is already declared.
-  IdentifierResolver::iterator I = IdResolver.begin(Name, GlobalCtx,
-                                                    /*CheckParent=*/false);
-
-  if (I != IdResolver.end()) {
-    NamedDecl *Decl = *I;
-    if (FunctionDecl *Fn = dyn_cast<FunctionDecl>(Decl)) {
-      // The return type fits. This is checked when the function is declared.
-      if (Fn->getNumParams() == 1 &&
-          Context.getCanonicalType(Fn->getParamDecl(0)->getType()) == Argument)
+  {
+    DeclContext::decl_iterator Alloc, AllocEnd;
+    for (llvm::tie(Alloc, AllocEnd) = GlobalCtx->lookup(Context, Name);
+         Alloc != AllocEnd; ++Alloc) {
+      // FIXME: Do we need to check for default arguments here?
+      FunctionDecl *Func = cast<FunctionDecl>(*Alloc);
+      if (Func->getNumParams() == 1 &&
+          Context.getCanonicalType(Func->getParamDecl(0)->getType()) == Argument)
         return;
-    } else if(OverloadedFunctionDecl *Ovl =
-                  dyn_cast<OverloadedFunctionDecl>(Decl)) {
-      for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(),
-                                                     FEnd = Ovl->function_end();
-               F != FEnd; ++F) {
-        if ((*F)->getNumParams() == 1 &&
-            Context.getCanonicalType((*F)->getParamDecl(0)->getType())
-                == Argument)
-          return;
-      }
     }
   }
 
@@ -548,6 +537,9 @@
                                            0, Argument, VarDecl::None, 0, 0);
   Alloc->setParams(&Param, 1);
 
+  // FIXME: Also add this declaration to the IdentifierResolver, but
+  // make sure it is at the end of the chain to coincide with the
+  // global scope.
   ((DeclContext *)TUScope->getEntity())->addDecl(Context, Alloc);
 }