r305195 - [Sema][C++1z] Ensure binding in dependent range for have non-null type

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 09:11:06 PDT 2017


Author: epilk
Date: Mon Jun 12 11:11:06 2017
New Revision: 305195

URL: http://llvm.org/viewvc/llvm-project?rev=305195&view=rev
Log:
[Sema][C++1z] Ensure binding in dependent range for have non-null type

Fixes PR32172

Differential revision: https://reviews.llvm.org/D34096

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=305195&r1=305194&r2=305195&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Jun 12 11:11:06 2017
@@ -2206,8 +2206,12 @@ Sema::BuildCXXForRangeStmt(SourceLocatio
 
     // Deduce any 'auto's in the loop variable as 'DependentTy'. We'll fill
     // them in properly when we instantiate the loop.
-    if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check)
+    if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
+      if (auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
+        for (auto *Binding : DD->bindings())
+          Binding->setType(Context.DependentTy);
       LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.DependentTy));
+    }
   } else if (!BeginDeclStmt.get()) {
     SourceLocation RangeLoc = RangeVar->getLocation();
 

Modified: cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp?rev=305195&r1=305194&r2=305195&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp Mon Jun 12 11:11:06 2017
@@ -70,4 +70,10 @@ int error_recovery() {
   return foobar_; // expected-error {{undeclared identifier 'foobar_'}}
 }
 
+// PR32172
+template <class T> void dependent_foreach(T t) {
+  for (auto [a,b,c] : t)
+    a,b,c;
+}
+
 // FIXME: by-value array copies




More information about the cfe-commits mailing list