From b8499f09faa1cf1e0a941f089974b86c345025ac Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Tue, 5 May 2015 19:17:03 +0000 Subject: 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 --- clang/lib/Sema/SemaDecl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'clang/lib/Sema/SemaDecl.cpp') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 00922f73a8e..7f4b3952807 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8710,7 +8710,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // If there is no declaration, there was an error parsing it. Just ignore // the initializer. if (!RealDecl || RealDecl->isInvalidDecl()) { - CorrectDelayedTyposInExpr(Init); + CorrectDelayedTyposInExpr(Init, dyn_cast_or_null(RealDecl)); return; } @@ -8744,11 +8744,12 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // Attempt typo correction early so that the type of the init expression can // be deduced based on the chosen correction:if the original init contains a // TypoExpr. - ExprResult Res = CorrectDelayedTyposInExpr(Init); + ExprResult Res = CorrectDelayedTyposInExpr(Init, VDecl); if (!Res.isUsable()) { RealDecl->setInvalidDecl(); return; } + if (Res.get() != Init) { Init = Res.get(); if (CXXDirectInit) @@ -8967,8 +8968,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // Try to correct any TypoExprs in the initialization arguments. for (size_t Idx = 0; Idx < Args.size(); ++Idx) { - ExprResult Res = - CorrectDelayedTyposInExpr(Args[Idx], [this, Entity, Kind](Expr *E) { + ExprResult Res = CorrectDelayedTyposInExpr( + Args[Idx], VDecl, [this, Entity, Kind](Expr *E) { InitializationSequence Init(*this, Entity, Kind, MultiExprArg(E)); return Init.Failed() ? ExprError() : E; }); -- cgit v1.2.3