]> granicus.if.org Git - clang/commitdiff
[Sema][C++1z] Ensure binding in dependent range for have non-null type
authorErik Pilkington <erik.pilkington@gmail.com>
Mon, 12 Jun 2017 16:11:06 +0000 (16:11 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Mon, 12 Jun 2017 16:11:06 +0000 (16:11 +0000)
Fixes PR32172

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305195 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/SemaCXX/cxx1z-decomposition.cpp

index 151b89ab8d2ab17fb87e086abe6491c6329364ca..0c35f9a571d4d5b603cd152fc086adf448ca69ce 100644 (file)
@@ -2206,8 +2206,12 @@ Sema::BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc,
 
     // 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();
 
index d457ace5d844e422df44adcc50b34239c8f49b47..7a4221784ad359986e9e7efe5e8c4f593cc7e2f3 100644 (file)
@@ -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