PR42104: Support instantiations of lambdas that implicitly capture
packs.
Two changes:
* Track odr-use via FunctionParmPackExprs to properly handle dependent
odr-uses of packs in generic lambdas.
* Do not instantiate implicit captures; instead, regenerate them by
instantiating the body of the lambda. This is necessary to
distinguish between cases where only one element of a pack is
captured and cases where the entire pack is captured.
This reinstates r362358 (reverted in r362375) with a fix for an
uninitialized variable use in UpdateMarkingForLValueToRValue.
llvm-svn: 362531
diff --git a/clang/lib/Sema/ScopeInfo.cpp b/clang/lib/Sema/ScopeInfo.cpp
index e84e592..b2a26af 100644
--- a/clang/lib/Sema/ScopeInfo.cpp
+++ b/clang/lib/Sema/ScopeInfo.cpp
@@ -229,20 +229,20 @@
return false;
}
-void LambdaScopeInfo::getPotentialVariableCapture(unsigned Idx, VarDecl *&VD,
- Expr *&E) const {
- assert(Idx < getNumPotentialVariableCaptures() &&
- "Index of potential capture must be within 0 to less than the "
- "number of captures!");
- E = PotentiallyCapturingExprs[Idx];
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
- VD = dyn_cast<VarDecl>(DRE->getFoundDecl());
- else if (MemberExpr *ME = dyn_cast<MemberExpr>(E))
- VD = dyn_cast<VarDecl>(ME->getMemberDecl());
- else
- llvm_unreachable("Only DeclRefExprs or MemberExprs should be added for "
- "potential captures");
- assert(VD);
+void LambdaScopeInfo::visitPotentialCaptures(
+ llvm::function_ref<void(VarDecl *, Expr *)> Callback) const {
+ for (Expr *E : PotentiallyCapturingExprs) {
+ if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
+ Callback(cast<VarDecl>(DRE->getFoundDecl()), E);
+ } else if (auto *ME = dyn_cast<MemberExpr>(E)) {
+ Callback(cast<VarDecl>(ME->getMemberDecl()), E);
+ } else if (auto *FP = dyn_cast<FunctionParmPackExpr>(E)) {
+ for (VarDecl *VD : *FP)
+ Callback(VD, E);
+ } else {
+ llvm_unreachable("unexpected expression in potential captures list");
+ }
+ }
}
FunctionScopeInfo::~FunctionScopeInfo() { }