From: Kaelyn Takata Date: Thu, 7 May 2015 00:11:02 +0000 (+0000) Subject: When performing delayed typo correction in a for-range loop's variable X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b705a232f5103799bb8862c87fad0def03d20091;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236682 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 0c0c60f1e4..5c72529caa 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/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/test/SemaCXX/typo-correction-cxx11.cpp b/test/SemaCXX/typo-correction-cxx11.cpp index 003d07edb3..99cb1662b7 100644 --- a/test/SemaCXX/typo-correction-cxx11.cpp +++ b/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); + } +} +}