From 0a31302fa11726ca749548a198eb3e98fbc59549 Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Thu, 20 Nov 2014 22:06:26 +0000 Subject: [PATCH] Correctly set the SourceRange a TypoCorrection will replace. Also clean up TypoCorrection::setCorrectionRange while we're at it. llvm-svn: 222460 --- clang/include/clang/Sema/TypoCorrection.h | 7 +++---- clang/lib/Sema/SemaLookup.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Sema/TypoCorrection.h b/clang/include/clang/Sema/TypoCorrection.h index 12f7f06..922d0ff 100644 --- a/clang/include/clang/Sema/TypoCorrection.h +++ b/clang/include/clang/Sema/TypoCorrection.h @@ -199,10 +199,9 @@ public: void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName) { - CorrectionRange.setBegin(ForceSpecifierReplacement && SS && !SS->isEmpty() - ? SS->getBeginLoc() - : TypoName.getLoc()); - CorrectionRange.setEnd(TypoName.getLoc()); + CorrectionRange = TypoName.getSourceRange(); + if (ForceSpecifierReplacement && SS && !SS->isEmpty()) + CorrectionRange.setBegin(SS->getBeginLoc()); } SourceRange getCorrectionRange() const { diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 44e3ce4..8b0ea32 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -3414,6 +3414,7 @@ void TypoCorrectionConsumer::addName(StringRef Name, NamedDecl *ND, TypoCorrection TC(&SemaRef.Context.Idents.get(Name), ND, NNS, ED); if (isKeyword) TC.makeKeyword(); + TC.setCorrectionRange(nullptr, Result.getLookupNameInfo()); addCorrection(TC); } @@ -3521,8 +3522,6 @@ bool TypoCorrectionConsumer::resolveCorrection(TypoCorrection &Candidate) { IdentifierInfo *Name = Candidate.getCorrectionAsIdentifierInfo(); DeclContext *TempMemberContext = MemberContext; CXXScopeSpec *TempSS = SS.get(); - if (Candidate.getCorrectionRange().isInvalid()) - Candidate.setCorrectionRange(TempSS, Result.getLookupNameInfo()); retry_lookup: LookupPotentialTypoResult(SemaRef, Result, Name, S, TempSS, TempMemberContext, EnteringContext, @@ -3563,6 +3562,7 @@ retry_lookup: QualifiedResults.push_back(Candidate); break; } + Candidate.setCorrectionRange(TempSS, Result.getLookupNameInfo()); return true; } return false; @@ -3628,8 +3628,10 @@ void TypoCorrectionConsumer::performQualifiedLookups() { TRD.getPair()) == Sema::AR_accessible) TC.addCorrectionDecl(*TRD); } - if (TC.isResolved()) + if (TC.isResolved()) { + TC.setCorrectionRange(SS.get(), Result.getLookupNameInfo()); addCorrection(TC); + } break; } case LookupResult::NotFound: -- 2.7.4