summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/ParseTentative.cpp
diff options
context:
space:
mode:
authorKaelyn Takata <rikka@google.com>2014-11-05 00:09:29 +0000
committerKaelyn Takata <rikka@google.com>2014-11-05 00:09:29 +0000
commit445b0657a50fbeefcdcd954f4779c8ae933e8d75 (patch)
treea32b9518ed51348a0ef837317fc9602b8ef5a4dd /clang/lib/Parse/ParseTentative.cpp
parentf20d7c4c6134cad587db861bfe46e27f2d46bc73 (diff)
downloadbcm5719-llvm-445b0657a50fbeefcdcd954f4779c8ae933e8d75.tar.gz
bcm5719-llvm-445b0657a50fbeefcdcd954f4779c8ae933e8d75.zip
Filter out non-static class members when correcting non-member-references.
llvm-svn: 221319
Diffstat (limited to 'clang/lib/Parse/ParseTentative.cpp')
-rw-r--r--clang/lib/Parse/ParseTentative.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 4b1375dfc18..944e88722f5 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1006,6 +1006,28 @@ bool Parser::isTentativelyDeclared(IdentifierInfo *II) {
!= TentativelyDeclaredIdentifiers.end();
}
+namespace {
+class TentativeParseCCC : public CorrectionCandidateCallback {
+public:
+ TentativeParseCCC(const Token &Next) {
+ WantRemainingKeywords = false;
+ WantTypeSpecifiers = Next.is(tok::l_paren) || Next.is(tok::r_paren) ||
+ Next.is(tok::greater) || Next.is(tok::l_brace) ||
+ Next.is(tok::identifier);
+ }
+
+ bool ValidateCandidate(const TypoCorrection &Candidate) override {
+ // Reject any candidate that only resolves to instance members since they
+ // aren't viable as standalone identifiers instead of member references.
+ if (Candidate.isResolved() && !Candidate.isKeyword() &&
+ std::all_of(Candidate.begin(), Candidate.end(),
+ [](NamedDecl *ND) { return ND->isCXXInstanceMember(); }))
+ return false;
+
+ return CorrectionCandidateCallback::ValidateCandidate(Candidate);
+ }
+};
+}
/// isCXXDeclarationSpecifier - Returns TPResult::True if it is a declaration
/// specifier, TPResult::False if it is not, TPResult::Ambiguous if it could
/// be either a decl-specifier or a function-style cast, and TPResult::Error
@@ -1131,14 +1153,8 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
// a parse error one way or another. In that case, tell the caller that
// this is ambiguous. Typo-correct to type and expression keywords and
// to types and identifiers, in order to try to recover from errors.
- auto TypoCorrection = llvm::make_unique<CorrectionCandidateCallback>();
- TypoCorrection->WantRemainingKeywords = false;
- TypoCorrection->WantTypeSpecifiers =
- Next.is(tok::l_paren) || Next.is(tok::r_paren) ||
- Next.is(tok::greater) || Next.is(tok::l_brace) ||
- Next.is(tok::identifier);
switch (TryAnnotateName(false /* no nested name specifier */,
- std::move(TypoCorrection))) {
+ llvm::make_unique<TentativeParseCCC>(Next))) {
case ANK_Error:
return TPResult::Error;
case ANK_TentativeDecl:
OpenPOWER on IntegriCloud