[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 23 16:18:15 PST 2025
================
@@ -4213,8 +4226,35 @@ class DecompositionDecl final
static DecompositionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
unsigned NumBindings);
- ArrayRef<BindingDecl *> bindings() const {
- return llvm::ArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
+ // Provide the range of bindings which may have a nested pack.
+ llvm::ArrayRef<BindingDecl *> bindings() const {
+ return {getTrailingObjects<BindingDecl *>(), NumBindings};
+ }
+
+ // Provide a flattened range to visit each binding.
+ auto flat_bindings() const {
+ llvm::ArrayRef<BindingDecl *> Bindings = bindings();
+ llvm::ArrayRef<Expr *> PackExprs;
+
+ // Split the bindings into subranges split by the pack.
+ auto S1 = Bindings.take_until(
+ [](BindingDecl *BD) { return BD->isParameterPack(); });
+
+ Bindings = Bindings.drop_front(S1.size());
+ if (!Bindings.empty()) {
+ PackExprs = Bindings.front()->getBindingPackExprs();
+ Bindings = Bindings.drop_front();
+ }
+
+ auto S2 = llvm::map_range(PackExprs, [](Expr *E) {
+ auto *DRE = cast<DeclRefExpr>(E);
+ return cast<BindingDecl>(DRE->getDecl());
+ });
+
+ // llvm::concat must take temporaries or it will capture
+ // references.
----------------
zygoloid wrote:
I found this comment a bit confusing, because `move` produces a reference rather than a temporary. How about something like "Pass xvalues to llvm::concat to request that it makes a copy."
https://github.com/llvm/llvm-project/pull/121417
More information about the cfe-commits
mailing list