[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)
Jason Rice via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 3 09:46:18 PST 2025
================
@@ -951,28 +959,130 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
return New;
}
+namespace {
+// CheckBindingsCount
+// - Checks the arity of the structured bindings
+// - Creates the resolved pack expr if there is
+// one
+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) {
+ TemplateTypeParmDecl *DummyTemplateParam = TemplateTypeParmDecl::Create(
+ S.Context, S.Context.getTranslationUnitDecl(),
+ /*KeyLoc*/ SourceLocation(), /*NameLoc*/ SourceLocation(),
+ /*TemplateDepth*/ 0, /*AutoParameterPosition*/ 0,
+ /*Identifier*/ nullptr, false, /*IsParameterPack*/ true);
----------------
ricejasonf wrote:
The first line of `getPackExpansionType` has an assert on `Pattern->containsUnexpandedParameterPack()`. Now that I am looking at it, there is a `ExpectsPackInType` parameter. Maybe that was not there before or I just missed it. I will try that.
https://github.com/llvm/llvm-project/pull/121417
More information about the cfe-commits
mailing list