================ @@ -951,28 +959,124 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D, return New; } +// CheckBindingsCount +// - Checks the arity of the structured bindings +// - Creates the resolved pack expr if there is +// one +static bool CheckBindingsCount(Sema &S, DecompositionDecl *DD, + QualType DecompType, + ArrayRef<BindingDecl *> Bindings, + unsigned MemberCount) { + auto BindingWithPackItr = + std::find_if(Bindings.begin(), Bindings.end(), + [](BindingDecl *D) -> bool { return D->isParameterPack(); }); + bool HasPack = BindingWithPackItr != Bindings.end(); + bool IsValid; + if (!HasPack) { + IsValid = Bindings.size() == MemberCount; + } else { + // there may not be more members than non-pack bindings + IsValid = MemberCount >= Bindings.size() - 1; + } + + if (IsValid && HasPack) { + // create the pack expr and assign it to the binding + unsigned PackSize = MemberCount - Bindings.size() + 1; + QualType PackType = S.Context.getPackExpansionType( + S.Context.DependentTy, std::nullopt, /*ExpectsPackInType=*/false); + BindingDecl *BD = (*BindingWithPackItr); + BD->setBinding(PackType, + ResolvedUnexpandedPackExpr::Create( + S.Context, DD->getBeginLoc(), DecompType, PackSize)); ---------------- ricejasonf wrote:
>(During the initial parse, we should treat a structured binding declaration >with a binding pack as being dependent, just like we treat a case where the >initializer has an unexpanded pack as dependent.) The BindingDecls are still created even when the initializer is dependent, and still the init expression is created after the DecompositionDecl even in template instantiation. (I remember trying this, but template instantation does not like instantiation of the same local decl twice.) https://github.com/llvm/llvm-project/pull/121417 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits