Author: rikka
Date: Wed May  6 19:11:02 2015
New Revision: 236682

URL: http://llvm.org/viewvc/llvm-project?rev=236682&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaCXX/typo-correction-cxx11.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=236682&r1=236681&r2=236682&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed May  6 19:11:02 2015
@@ -1828,6 +1828,15 @@ Sema::ActOnObjCForCollectionStmt(SourceL
 /// \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;

Modified: cfe/trunk/test/SemaCXX/typo-correction-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-cxx11.cpp?rev=236682&r1=236681&r2=236682&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-cxx11.cpp Wed May  6 19:11:02 2015
@@ -23,3 +23,12 @@ void test(int aaa, int bbb, int thisvar)
   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);
+  }
+}
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to