From fb8cf4087d21a56186426fe8339bf25e47a4001b Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Thu, 7 May 2015 00:11:02 +0000 Subject: When performing delayed typo correction in a for-range loop's variable declaration, ensure the loop variable is properly marked as invalid when it is an "auto" variable. llvm-svn: 236682 --- clang/lib/Sema/SemaStmt.cpp | 9 +++++++++ clang/test/SemaCXX/typo-correction-cxx11.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'clang') diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 0c0c60f1e4e..5c72529caa8 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1828,6 +1828,15 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, /// \return true if an error occurs. static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID) { + if (Decl->getType()->isUndeducedType()) { + ExprResult Res = SemaRef.CorrectDelayedTyposInExpr(Init); + if (!Res.isUsable()) { + Decl->setInvalidDecl(); + return true; + } + Init = Res.get(); + } + // Deduce the type for the iterator variable now rather than leaving it to // AddInitializerToDecl, so we can produce a more suitable diagnostic. QualType InitType; diff --git a/clang/test/SemaCXX/typo-correction-cxx11.cpp b/clang/test/SemaCXX/typo-correction-cxx11.cpp index 003d07edb3c..99cb1662b7a 100644 --- a/clang/test/SemaCXX/typo-correction-cxx11.cpp +++ b/clang/test/SemaCXX/typo-correction-cxx11.cpp @@ -23,3 +23,12 @@ void test(int aaa, int bbb, int thisvar) { // expected-note {{'thisvar' declare int thatval = aaa * (bbb + thatvar); // expected-error {{use of undeclared identifier 'thatvar'; did you mean 'thisvar'?}} } } + +namespace PR18854 { +void f() { + for (auto&& x : e) { // expected-error-re {{use of undeclared identifier 'e'{{$}}}} + auto Functor = [x]() {}; + long Alignment = __alignof__(Functor); + } +} +} -- cgit v1.2.3