]> granicus.if.org Git - clang/commitdiff
When performing delayed typo correction in a for-range loop's variable
authorKaelyn Takata <rikka@google.com>
Thu, 7 May 2015 00:11:02 +0000 (00:11 +0000)
committerKaelyn Takata <rikka@google.com>
Thu, 7 May 2015 00:11:02 +0000 (00:11 +0000)
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

lib/Sema/SemaStmt.cpp
test/SemaCXX/typo-correction-cxx11.cpp

index 0c0c60f1e4e2c4681e640ec60de09e6bd5999614..5c72529caa8a2e420d6d3c1554a139a8801ff06f 100644 (file)
@@ -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;
index 003d07edb3c15dd0bf7f1a13acaf160410cb5e83..99cb1662b7a045e847cf93d56c6d49b99dc95ae2 100644 (file)
@@ -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);
+  }
+}
+}