diff options
author | Kaelyn Takata <rikka@google.com> | 2015-05-05 19:17:03 +0000 |
---|---|---|
committer | Kaelyn Takata <rikka@google.com> | 2015-05-05 19:17:03 +0000 |
commit | b8499f09faa1cf1e0a941f089974b86c345025ac (patch) | |
tree | 980304ad7d402887735bd4bb60dcc0a7764cfe5a /clang/lib/Sema/SemaExprCXX.cpp | |
parent | 336d90b61bcc3862ac1fc016834340b6ef79cc4b (diff) | |
download | bcm5719-llvm-b8499f09faa1cf1e0a941f089974b86c345025ac.tar.gz bcm5719-llvm-b8499f09faa1cf1e0a941f089974b86c345025ac.zip |
Allow TransformTypos to ignore corrections to a specified VarDecl.
This is needed to prevent a TypoExpr from being corrected to a variable
when the TypoExpr is a subexpression of that variable's initializer.
Also exclude more keywords from the correction candidate pool when the
subsequent token is .* or ->* since keywords like "new" or "return"
aren't valid on the left side of those operators.
Fixes PR23140.
llvm-svn: 236519
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index bb67939ad89..b853eaefbe4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -6138,6 +6138,8 @@ public: class TransformTypos : public TreeTransform<TransformTypos> { typedef TreeTransform<TransformTypos> BaseTransform; + VarDecl *InitDecl; // A decl to avoid as a correction because it is in the + // process of being initialized. llvm::function_ref<ExprResult(Expr *)> ExprFilter; llvm::SmallSetVector<TypoExpr *, 2> TypoExprs, AmbiguousTypoExprs; llvm::SmallDenseMap<TypoExpr *, ExprResult, 2> TransformCache; @@ -6216,8 +6218,8 @@ class TransformTypos : public TreeTransform<TransformTypos> { } public: - TransformTypos(Sema &SemaRef, llvm::function_ref<ExprResult(Expr *)> Filter) - : BaseTransform(SemaRef), ExprFilter(Filter) {} + TransformTypos(Sema &SemaRef, VarDecl *InitDecl, llvm::function_ref<ExprResult(Expr *)> Filter) + : BaseTransform(SemaRef), InitDecl(InitDecl), ExprFilter(Filter) {} ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, @@ -6296,6 +6298,8 @@ public: // For the first TypoExpr and an uncached TypoExpr, find the next likely // typo correction and return it. while (TypoCorrection TC = State.Consumer->getNextCorrection()) { + if (InitDecl && TC.getCorrectionDecl() == InitDecl) + continue; ExprResult NE = State.RecoveryHandler ? State.RecoveryHandler(SemaRef, E, TC) : attemptRecovery(SemaRef, *State.Consumer, TC); @@ -6320,8 +6324,9 @@ public: }; } -ExprResult Sema::CorrectDelayedTyposInExpr( - Expr *E, llvm::function_ref<ExprResult(Expr *)> Filter) { +ExprResult +Sema::CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl, + llvm::function_ref<ExprResult(Expr *)> Filter) { // If the current evaluation context indicates there are uncorrected typos // and the current expression isn't guaranteed to not have typos, try to // resolve any TypoExpr nodes that might be in the expression. @@ -6332,7 +6337,7 @@ ExprResult Sema::CorrectDelayedTyposInExpr( assert(TyposInContext < ~0U && "Recursive call of CorrectDelayedTyposInExpr"); ExprEvalContexts.back().NumTypos = ~0U; auto TyposResolved = DelayedTypos.size(); - auto Result = TransformTypos(*this, Filter).Transform(E); + auto Result = TransformTypos(*this, InitDecl, Filter).Transform(E); ExprEvalContexts.back().NumTypos = TyposInContext; TyposResolved -= DelayedTypos.size(); if (Result.isInvalid() || Result.get() != E) { |