diff options
Diffstat (limited to 'clang/lib/Sema/ScopeInfo.cpp')
-rw-r--r-- | clang/lib/Sema/ScopeInfo.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/clang/lib/Sema/ScopeInfo.cpp b/clang/lib/Sema/ScopeInfo.cpp index e84e592a482..b2a26af9b4a 100644 --- a/clang/lib/Sema/ScopeInfo.cpp +++ b/clang/lib/Sema/ScopeInfo.cpp @@ -229,20 +229,20 @@ bool CapturingScopeInfo::isVLATypeCaptured(const VariableArrayType *VAT) const { 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() { } |