[PATCH] D34096: [Sema][C++1z] Ensure structured binding's bindings in dependent foreach have non-null type
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 11 18:31:01 PDT 2017
erik.pilkington created this revision.
A DecompositionDecls' bindings have a null type until the initializer is attached, if the initializer is dependent, then the bindings should be set to have dependent type. For non-foreach bindings, this is done in Sema::CheckCompleteDecompositionDeclaration(), this patch ensures that this is done to bindings in a foreach as well. Fixes PR32172.
Thanks for taking a look!
Erik
https://reviews.llvm.org/D34096
Files:
lib/Sema/SemaStmt.cpp
test/SemaCXX/cxx1z-decomposition.cpp
Index: test/SemaCXX/cxx1z-decomposition.cpp
===================================================================
--- test/SemaCXX/cxx1z-decomposition.cpp
+++ test/SemaCXX/cxx1z-decomposition.cpp
@@ -70,4 +70,10 @@
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
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2206,8 +2206,12 @@
// 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34096.102149.patch
Type: text/x-patch
Size: 1193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170612/00d94b98/attachment-0001.bin>
More information about the cfe-commits
mailing list