diff options
author | Kaelyn Takata <rikka@google.com> | 2014-04-04 22:16:30 +0000 |
---|---|---|
committer | Kaelyn Takata <rikka@google.com> | 2014-04-04 22:16:30 +0000 |
commit | 67d8fe3f69bfb586f3cda59659337caf90e00756 (patch) | |
tree | 798f5869157a968dbc70d8e87f1fd8c612e6e1ab /lib/Sema/SemaExpr.cpp | |
parent | 531ba2d1b9b4728ee5a80c475d9617bf45867bab (diff) | |
download | clang-67d8fe3f69bfb586f3cda59659337caf90e00756.tar.gz clang-67d8fe3f69bfb586f3cda59659337caf90e00756.tar.bz2 clang-67d8fe3f69bfb586f3cda59659337caf90e00756.tar.xz |
Try harder about not suggesting methods as corrections when they
obviously won't work. Specifically, don't suggest methods (static or
not) from unrelated classes when the expression is a method call
through a specific object.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205653 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7894682efc..c6e3e23fdd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3974,8 +3974,8 @@ namespace { class FunctionCallCCC : public FunctionCallFilterCCC { public: FunctionCallCCC(Sema &SemaRef, const IdentifierInfo *FuncName, - unsigned NumArgs, bool HasExplicitTemplateArgs) - : FunctionCallFilterCCC(SemaRef, NumArgs, HasExplicitTemplateArgs), + unsigned NumArgs, MemberExpr *ME) + : FunctionCallFilterCCC(SemaRef, NumArgs, false, ME), FunctionName(FuncName) {} bool ValidateCandidate(const TypoCorrection &candidate) override { @@ -3992,17 +3992,20 @@ private: }; } -static TypoCorrection TryTypoCorrectionForCall(Sema &S, - DeclarationNameInfo FuncName, +static TypoCorrection TryTypoCorrectionForCall(Sema &S, Expr *Fn, + FunctionDecl *FDecl, ArrayRef<Expr *> Args) { - FunctionCallCCC CCC(S, FuncName.getName().getAsIdentifierInfo(), - Args.size(), false); - if (TypoCorrection Corrected = - S.CorrectTypo(FuncName, Sema::LookupOrdinaryName, - S.getScopeForContext(S.CurContext), NULL, CCC)) { + MemberExpr *ME = dyn_cast<MemberExpr>(Fn); + DeclarationName FuncName = FDecl->getDeclName(); + SourceLocation NameLoc = ME ? ME->getMemberLoc() : Fn->getLocStart(); + FunctionCallCCC CCC(S, FuncName.getAsIdentifierInfo(), Args.size(), ME); + + if (TypoCorrection Corrected = S.CorrectTypo( + DeclarationNameInfo(FuncName, NameLoc), Sema::LookupOrdinaryName, + S.getScopeForContext(S.CurContext), NULL, CCC)) { if (NamedDecl *ND = Corrected.getCorrectionDecl()) { if (Corrected.isOverloaded()) { - OverloadCandidateSet OCS(FuncName.getLoc()); + OverloadCandidateSet OCS(NameLoc); OverloadCandidateSet::iterator Best; for (TypoCorrection::decl_iterator CD = Corrected.begin(), CDEnd = Corrected.end(); @@ -4011,7 +4014,7 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, S.AddOverloadCandidate(FD, DeclAccessPair::make(FD, AS_none), Args, OCS); } - switch (OCS.BestViableFunction(S, FuncName.getLoc(), Best)) { + switch (OCS.BestViableFunction(S, NameLoc, Best)) { case OR_Success: ND = Best->Function; Corrected.setCorrectionDecl(ND); @@ -4062,13 +4065,8 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, // arguments for the remaining parameters), don't make the call. if (Args.size() < NumParams) { if (Args.size() < MinArgs) { - MemberExpr *ME = dyn_cast<MemberExpr>(Fn); TypoCorrection TC; - if (FDecl && (TC = TryTypoCorrectionForCall( - *this, DeclarationNameInfo(FDecl->getDeclName(), - (ME ? ME->getMemberLoc() - : Fn->getLocStart())), - Args))) { + if (FDecl && (TC = TryTypoCorrectionForCall(*this, Fn, FDecl, Args))) { unsigned diag_id = MinArgs == NumParams && !Proto->isVariadic() ? diag::err_typecheck_call_too_few_args_suggest @@ -4103,13 +4101,8 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, // them. if (Args.size() > NumParams) { if (!Proto->isVariadic()) { - MemberExpr *ME = dyn_cast<MemberExpr>(Fn); TypoCorrection TC; - if (FDecl && (TC = TryTypoCorrectionForCall( - *this, DeclarationNameInfo(FDecl->getDeclName(), - (ME ? ME->getMemberLoc() - : Fn->getLocStart())), - Args))) { + if (FDecl && (TC = TryTypoCorrectionForCall(*this, Fn, FDecl, Args))) { unsigned diag_id = MinArgs == NumParams && !Proto->isVariadic() ? diag::err_typecheck_call_too_many_args_suggest |