summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2017-06-12 16:11:06 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2017-06-12 16:11:06 +0000
commit21ff345d64b99b96a090aa1276d98fef4be2de1f (patch)
tree1d1c32c2080df758a4abd599d9cc46cd4aa7f9f1
parentfd02314113546b7a90b1a26f957be7f5a855c790 (diff)
downloadbcm5719-llvm-21ff345d64b99b96a090aa1276d98fef4be2de1f.tar.gz
bcm5719-llvm-21ff345d64b99b96a090aa1276d98fef4be2de1f.zip
[Sema][C++1z] Ensure binding in dependent range for have non-null type
Fixes PR32172 Differential revision: https://reviews.llvm.org/D34096 llvm-svn: 305195
-rw-r--r--clang/lib/Sema/SemaStmt.cpp6
-rw-r--r--clang/test/SemaCXX/cxx1z-decomposition.cpp6
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 151b89ab8d2..0c35f9a571d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -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();
diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index d457ace5d84..7a4221784ad 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -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
OpenPOWER on IntegriCloud