[llvm-branch-commits] [clang] [Clang] [C++26] Expansion Statements (Part 6: Destructuring Expansion Statements) (PR #169685)

Shafik Yaghmour via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 9 10:46:29 PDT 2026


================
@@ -388,8 +428,65 @@ StmtResult Sema::BuildNonEnumeratingCXXExpansionStmtPattern(
         Data.IterDecl, LParenLoc, ColonLoc, RParenLoc);
   }
 
-  Diag(ESD->getLocation(), diag::err_expansion_statements_todo);
-  return StmtError();
+  // If not, try destructuring.
+  StmtResult DecompDeclStmt = BuildDestructuringDecompositionDecl(
+      *this, ExpansionInitializer, ColonLoc, ExpansionVar->isConstexpr(),
+      LifetimeExtendTemps);
+  if (DecompDeclStmt.isInvalid()) {
+    Diag(ExpansionInitializer->getBeginLoc(),
+         diag::err_expansion_stmt_invalid_init)
+        << ExpansionInitializer->getType()
+        << ExpansionInitializer->getSourceRange();
+
+    ActOnInitializerError(ExpansionVar);
+    return StmtError();
+  }
+
+  auto *DS = DecompDeclStmt.getAs<DeclStmt>();
+  auto *DD = cast<DecompositionDecl>(DS->getSingleDecl());
+  if (DD->isInvalidDecl())
+    return StmtError();
+
+  // Synthesise an InitListExpr to store the bindings; this essentially lets us
+  // desugar the expansion of a destructuring expansion statement to that of an
+  // enumerating expansion statement.
+  SmallVector<Expr *> Bindings;
+  Bindings.reserve(DD->bindings().size());
----------------
shafik wrote:

I almost wonder if this is a premature optimization, I don't think we have data one way or the other.

https://github.com/llvm/llvm-project/pull/169685


More information about the llvm-branch-commits mailing list