Doug,

Here's a the patch building on my previous overloaded function resolution
patch. In addition to handling template functions properly when doing the
overload resolution (which turned out to be easier than anticipated), it
also fixes tiny bug in my previous patch that lead to no error message being
printed out if the call to BestViableFunction did not succeed. I have a
couple of questions about the remaining cases you mentioned in the thread
for my previous patch:

  1. For the case of member functions, were referring to when the typo
correction is being done on a member function called from within another
member function ("class X { void foo(); void b() { fio(); };", correcting
fio to foo) or when one is called through "." or "->" ("void b() { X x;
x.fio(); }" and correcting x.fio to x.foo)? The former case seems to work
already, and the latter is not handled by DiagnoseEmptyLookup but by
LookupMemberExprInRecord in SemaExprMember.cpp.

  2. What exactly was the situation you were referring to when you said "we
could see using declarations (which we'd need to look through) or unresolved
using declarations (which we'd probably just give up on)"? That given e.g.

   namespace NS { void foo(double); }
   void foo(int);
   using namespace NS;
   void bar() { Foo(0.5); }

both foo(int) and foo(double) from NS should be candidates for overload
resolution when correcting Foo(0.5), and when "foo" is suggested as a
correction the note points foo(double)?

Thanks,
Kaelyn
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index d9b320d..54bb758 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -2237,6 +2237,7 @@ public:
 
   bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
                            CorrectTypoContext CTC = CTC_Unknown,
+                           TemplateArgumentListInfo *ExplicitTemplateArgs = 0,
                            Expr **Args = 0, unsigned NumArgs = 0);
 
   ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II,
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 6ace3e9..bc7d0bd 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1364,8 +1364,9 @@ Sema::DecomposeUnqualifiedId(const UnqualifiedId &Id,
 ///
 /// \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,18 +1459,20 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
                                         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:
             ND = Best->Function;
             break;
           default:
-            // Don't try to recover; it won't work.
-            return true;
+            break;
         }
       }
       R.addDecl(ND);
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 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
                               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");
diff --git a/test/SemaCXX/function-overload-typo-crash.cpp b/test/SemaCXX/function-overload-typo-crash.cpp
index 580f27a..8c5cec8 100644
--- a/test/SemaCXX/function-overload-typo-crash.cpp
+++ b/test/SemaCXX/function-overload-typo-crash.cpp
@@ -10,3 +10,19 @@ void f() {
   fin(); //expected-error {{use of undeclared identifier 'fin'; did you mean 'min'}}
   fax(0); //expected-error {{use of undeclared identifier 'fax'; did you mean 'max'}}
 }
+
+template <typename T> void somefunc(T*, T*); //expected-note {{'somefunc' declared here}}
+template <typename T> void somefunc(const T[]); //expected-note {{'somefunc' declared here}}
+template <typename T1, typename T2> void somefunc(T1*, T2*); //expected-note {{'somefunc' declared here}}
+template <typename T1, typename T2> void somefunc(T1*, const T2[]); //expected-note 2 {{'somefunc' declared here}}
+
+void c() {
+  int *i = 0, *j = 0;
+  const int x[] = {1, 2, 3};
+  long *l = 0;
+  somefun(i, j); //expected-error {{use of undeclared identifier 'somefun'; did you mean 'somefunc'?}}
+  somefun(x); //expected-error {{use of undeclared identifier 'somefun'; did you mean 'somefunc'?}}
+  somefun(i, l); //expected-error {{use of undeclared identifier 'somefun'; did you mean 'somefunc'?}}
+  somefun(l, x); //expected-error {{use of undeclared identifier 'somefun'; did you mean 'somefunc'?}}
+  somefun(i, x); //expected-error {{use of undeclared identifier 'somefun'; did you mean 'somefunc'?}}
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to