Skip to content

Commit

Permalink
[Sema][C++1z] Ensure binding in dependent range for have non-null type
Browse files Browse the repository at this point in the history
Fixes PR32172

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

llvm-svn: 305195
  • Loading branch information
epilk committed Jun 12, 2017
1 parent fd02314 commit 21ff345
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaStmt.cpp
Expand Up @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/cxx1z-decomposition.cpp
Expand Up @@ -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

0 comments on commit 21ff345

Please sign in to comment.