[cfe-commits] r136948 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/function-overload-typo-crash.cpp

Kaelyn Uhrain rikka at google.com
Thu Aug 4 17:09:52 PDT 2011


Author: rikka
Date: Thu Aug  4 19:09:52 2011
New Revision: 136948

URL: http://llvm.org/viewvc/llvm-project?rev=136948&view=rev
Log:
Have the typo correction in DiagnoseEmptyLookup properly handle template
functions when performing function overload resolution.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=136948&r1=136947&r2=136948&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug  4 19:09:52 2011
@@ -2265,6 +2265,7 @@
 
   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,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=136948&r1=136947&r2=136948&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Aug  4 19:09:52 2011
@@ -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:

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=136948&r1=136947&r2=136948&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug  4 19:09:52 2011
@@ -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");

Modified: cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp?rev=136948&r1=136947&r2=136948&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp Thu Aug  4 19:09:52 2011
@@ -11,20 +11,17 @@
   fax(0); //expected-error {{use of undeclared identifier 'fax'; did you mean 'max'}}
 }
 
-// TODO: Add proper function overloading resolution for template functions
-template <typename T> void somefunc(T*, T*);
-template <typename T> void somefunc(const T[]);
-template <typename T1, typename T2> void somefunc(T1*, T2*);
-template <typename T1, typename T2> void somefunc(T1*, const T2[]); //expected-note 5 {{'somefunc' declared here}} \
-                                                                    //expected-note {{candidate function template not viable: requires 2 arguments, but 1 was provided}} TODO this shouldn't happen
+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'?}} \
-              //expected-error {{no matching function for call to 'somefunc'}} TODO this shouldn't happen
+  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'?}}





More information about the cfe-commits mailing list