Add iterators to LookupResult, allowing one to iterate over the
non-ambiguous name lookup results without allocating any memory, e.g.,
for sets of overloaded functions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63549 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fe7ab92..d03879e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1666,35 +1666,22 @@
         << D.getCXXScopeSpec().getRange();
       InvalidDecl = true;
         
-      PrevDecl = LookupQualifiedName(DC, Name, LookupOrdinaryName);
-      if (!PrevDecl) {
-        // Nothing to suggest.
-      } else if (OverloadedFunctionDecl *Ovl 
-                 = dyn_cast<OverloadedFunctionDecl>(PrevDecl)) {
-        for (OverloadedFunctionDecl::function_iterator 
-               Func = Ovl->function_begin(),
-               FuncEnd = Ovl->function_end();
-             Func != FuncEnd; ++Func) {
-          if (isNearlyMatchingMemberFunction(Context, *Func, NewFD))
-            Diag((*Func)->getLocation(), diag::note_member_def_close_match);
-            
-        }
-      } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(PrevDecl)) {
-        // Suggest this no matter how mismatched it is; it's the only
-        // thing we have.
-        unsigned diag;
-        if (isNearlyMatchingMemberFunction(Context, Method, NewFD))
-          diag = diag::note_member_def_close_match;
-        else if (Method->getBody())
-          diag = diag::note_previous_definition;
-        else
-          diag = diag::note_previous_declaration;
-        Diag(Method->getLocation(), diag);
+      LookupResult Prev = LookupQualifiedName(DC, Name, LookupOrdinaryName, 
+                                              true);
+      assert(!Prev.isAmbiguous() && 
+             "Cannot have an ambiguity in previous-declaration lookup");
+      for (LookupResult::iterator Func = Prev.begin(), FuncEnd = Prev.end();
+           Func != FuncEnd; ++Func) {
+        if (isa<CXXMethodDecl>(*Func) &&
+            isNearlyMatchingMemberFunction(Context, cast<FunctionDecl>(*Func),
+                                           NewFD))
+          Diag((*Func)->getLocation(), diag::note_member_def_close_match);
       }
-        
+ 
       PrevDecl = 0;
     }
   }
+
   // Handle attributes. We need to have merged decls when handling attributes
   // (for example to check for conflicts, etc).
   ProcessDeclAttributes(NewFD, D);