Have the typo correction in DiagnoseEmptyLookup properly handle template
functions when performing function overload resolution.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136948 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ffa092a..bc7d0bd 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1364,8 +1364,9 @@
 ///
 /// \return false if new lookup candidates were found
 bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
-                               CorrectTypoContext CTC, Expr **Args,
-                               unsigned NumArgs) {
+                               CorrectTypoContext CTC,
+                               TemplateArgumentListInfo *ExplicitTemplateArgs,
+                               Expr **Args, unsigned NumArgs) {
   DeclarationName Name = R.getLookupName();
 
   unsigned diagnostic = diag::err_undeclared_var_use;
@@ -1458,10 +1459,13 @@
                                         CDEnd = Corrected.end();
              CD != CDEnd; ++CD) {
           if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*CD))
-            AddOverloadCandidate(FD, DeclAccessPair::make(*CD, AS_none),
+            AddOverloadCandidate(FD, DeclAccessPair::make(FD, AS_none),
                                  Args, NumArgs, OCS);
-          // TODO: Handle FunctionTemplateDecl and other Decl types that
-          // support overloading and could be corrected by CorrectTypo.
+          else if (FunctionTemplateDecl *FTD =
+                   dyn_cast<FunctionTemplateDecl>(*CD))
+            AddTemplateOverloadCandidate(
+                FTD, DeclAccessPair::make(FTD, AS_none), ExplicitTemplateArgs,
+                Args, NumArgs, OCS);
         }
         switch (OCS.BestViableFunction(*this, R.getNameLoc(), Best)) {
           case OR_Success:
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 712720b..72a43d8 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -8221,7 +8221,7 @@
                               ExplicitTemplateArgs, Args, NumArgs) &&
       (!EmptyLookup ||
        SemaRef.DiagnoseEmptyLookup(S, SS, R, Sema::CTC_Expression,
-                                   Args, NumArgs)))
+                                   ExplicitTemplateArgs, Args, NumArgs)))
     return ExprError();
 
   assert(!R.empty() && "lookup results empty despite recovery");