diff options
author | Kaelyn Uhrain <rikka@google.com> | 2012-01-13 23:10:36 +0000 |
---|---|---|
committer | Kaelyn Uhrain <rikka@google.com> | 2012-01-13 23:10:36 +0000 |
commit | 637b5b3235eea7840e99acf7e12b9aa127b4a44c (patch) | |
tree | 02ec9afbd89d92397a1d60137d6faa2da904523e /clang/lib/Sema/SemaTemplateVariadic.cpp | |
parent | 81bd038623cf5c8f93bdd6b31b3ec37497993d3d (diff) | |
download | bcm5719-llvm-637b5b3235eea7840e99acf7e12b9aa127b4a44c.tar.gz bcm5719-llvm-637b5b3235eea7840e99acf7e12b9aa127b4a44c.zip |
Convert SemaTemplate*.cpp to pass a callback object to CorrectTypo.
The change to SemaTemplateVariadic.cpp improves the typo correction
results in certain situations, while the change to SemaTemplate.cpp
does not change existing behavior.
llvm-svn: 148155
Diffstat (limited to 'clang/lib/Sema/SemaTemplateVariadic.cpp')
-rw-r--r-- | clang/lib/Sema/SemaTemplateVariadic.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index b219c20459f..44242f1c137 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -708,6 +708,19 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) { return false; } +namespace { + +// Callback to only accept typo corrections that refer to parameter packs. +class ParameterPackValidatorCCC : public CorrectionCandidateCallback { + public: + virtual bool ValidateCandidate(const TypoCorrection &candidate) { + NamedDecl *ND = candidate.getCorrectionDecl(); + return ND && ND->isParameterPack(); + } +}; + +} + /// \brief Called when an expression computing the size of a parameter pack /// is parsed. /// @@ -733,6 +746,7 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, LookupName(R, S); NamedDecl *ParameterPack = 0; + ParameterPackValidatorCCC Validator; switch (R.getResultKind()) { case LookupResult::Found: ParameterPack = R.getFoundDecl(); @@ -741,19 +755,16 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, case LookupResult::NotFound: case LookupResult::NotFoundInCurrentInstantiation: if (TypoCorrection Corrected = CorrectTypo(R.getLookupNameInfo(), - R.getLookupKind(), S, 0, 0, - false, CTC_NoKeywords)) { - if (NamedDecl *CorrectedResult = Corrected.getCorrectionDecl()) - if (CorrectedResult->isParameterPack()) { - std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions())); - ParameterPack = CorrectedResult; - Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest) - << &Name << CorrectedQuotedStr - << FixItHint::CreateReplacement( - NameLoc, Corrected.getAsString(getLangOptions())); - Diag(ParameterPack->getLocation(), diag::note_parameter_pack_here) - << CorrectedQuotedStr; - } + R.getLookupKind(), S, 0, + &Validator)) { + std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions())); + ParameterPack = Corrected.getCorrectionDecl(); + Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest) + << &Name << CorrectedQuotedStr + << FixItHint::CreateReplacement( + NameLoc, Corrected.getAsString(getLangOptions())); + Diag(ParameterPack->getLocation(), diag::note_parameter_pack_here) + << CorrectedQuotedStr; } case LookupResult::FoundOverloaded: |