r187467 - Fix a crasher than manifests when typo correction suggests a function template.

Richard Trieu rtrieu at google.com
Tue Jul 30 17:48:10 PDT 2013


Author: rtrieu
Date: Tue Jul 30 19:48:10 2013
New Revision: 187467

URL: http://llvm.org/viewvc/llvm-project?rev=187467&view=rev
Log:
Fix a crasher than manifests when typo correction suggests a function template.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=187467&r1=187466&r2=187467&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul 30 19:48:10 2013
@@ -3932,7 +3932,7 @@ Sema::ConvertArgumentsForCall(CallExpr *
             << Fn->getSourceRange() << CorrectedQuotedStr
             << FixItHint::CreateReplacement(TC.getCorrectionRange(),
                                             CorrectedStr);
-        Diag(TC.getCorrectionDeclAs<FunctionDecl>()->getLocStart(),
+        Diag(TC.getCorrectionDecl()->getLocStart(),
              diag::note_previous_decl) << CorrectedQuotedStr;
       } else if (MinArgs == 1 && FDecl && FDecl->getParamDecl(0)->getDeclName())
         Diag(RParenLoc, MinArgs == NumArgsInProto && !Proto->isVariadic()
@@ -3978,7 +3978,7 @@ Sema::ConvertArgumentsForCall(CallExpr *
             << Fn->getSourceRange() << CorrectedQuotedStr
             << FixItHint::CreateReplacement(TC.getCorrectionRange(),
                                             CorrectedStr);
-        Diag(TC.getCorrectionDeclAs<FunctionDecl>()->getLocStart(),
+        Diag(TC.getCorrectionDecl()->getLocStart(),
              diag::note_previous_decl) << CorrectedQuotedStr;
       } else if (NumArgsInProto == 1 && FDecl && FDecl->getParamDecl(0)->getDeclName())
         Diag(Args[NumArgsInProto]->getLocStart(),

Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=187467&r1=187466&r2=187467&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Tue Jul 30 19:48:10 2013
@@ -14,3 +14,22 @@ void zif::nab(int) {
   nab();  // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
 }
 }
+
+namespace TemplateFunction {
+template <class T>  // expected-note {{'::TemplateFunction::A' declared here}}
+void A(T) { }
+
+template <class T>  // expected-note {{'::TemplateFunction::B' declared here}}
+void B(T) { }
+
+class Foo {
+ public:
+  void A(int, int) {}
+  void B() {}
+};
+
+void test(Foo F, int num) {
+  F.A(num);  // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::A'?}}
+  F.B(num);  // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::B'?}}
+}
+}





More information about the cfe-commits mailing list