[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
================
@@ -234,6 +234,46 @@ static IterableExpansionStmtData TryBuildIterableExpansionStmtInitializer(
#endif
}
+static StmtResult BuildDestructuringDecompositionDecl(
+ Sema &S, Expr *ExpansionInitializer, SourceLocation ColonLoc,
+ bool VarIsConstexpr,
+ ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
+ auto Ctx = Sema::ExpressionEvaluationContext::PotentiallyEvaluated;
+ if (VarIsConstexpr)
+ Ctx = Sema::ExpressionEvaluationContext::ImmediateFunctionContext;
+ EnterExpressionEvaluationContext ExprEvalCtx(S, Ctx);
+
+ // The declarations should be attached to the parent decl context.
+ Sema::ContextRAII CtxGuard(S, S.CurContext->getParent(),
+ /*NewThis=*/false);
+
+ UnsignedOrNone Arity =
+ S.GetDecompositionElementCount(ExpansionInitializer->getType(), ColonLoc);
+
+ if (!Arity)
+ return StmtError();
+
+ QualType AutoRRef = S.Context.getAutoRRefDeductType();
+ SmallVector<BindingDecl *> Bindings;
+ for (unsigned I = 0; I < *Arity; ++I)
+ Bindings.push_back(BindingDecl::Create(
+ S.Context, S.CurContext, ColonLoc,
+ S.getPreprocessor().getIdentifierInfo("__u" + std::to_string(I)),
----------------
shafik wrote:
So naming these things has me asking myself some questions. I think naming them does make sense but what happens if we have a local inside a expansion and it has the same name will they conflict?
How does the line numbering look for a diagnostic?
I would like to see tests of this scenario with a local inside the expansion with a name matching this. Yes, it would be IFNDR but we should test it.
https://github.com/llvm/llvm-project/pull/169685
More information about the llvm-branch-commits
mailing list