[Clang][P1061] Fix invalid pack binding crash (#135129)

This commit is contained in:
Jason Rice 2025-04-10 17:12:11 -07:00 committed by GitHub
parent a62b9b387f
commit 2f29829475
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -4281,7 +4281,7 @@ public:
[](BindingDecl *BD) { return BD->isParameterPack(); });
Bindings = Bindings.drop_front(BeforePackBindings.size());
if (!Bindings.empty()) {
if (!Bindings.empty() && Bindings.front()->getBinding()) {
PackBindings = Bindings.front()->getBindingPackDecls();
Bindings = Bindings.drop_front();
}

View File

@ -1597,11 +1597,10 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
auto *NewDD = cast_if_present<DecompositionDecl>(
VisitVarDecl(D, /*InstantiatingVarTemplate=*/false, &NewBindingArray));
if (!NewDD || NewDD->isInvalidDecl())
if (!NewDD || NewDD->isInvalidDecl()) {
for (auto *NewBD : NewBindings)
NewBD->setInvalidDecl();
if (OldBindingPack) {
} else if (OldBindingPack) {
// Mark the bindings in the pack as instantiated.
auto Bindings = NewDD->bindings();
BindingDecl *NewBindingPack = *llvm::find_if(

View File

@ -3,9 +3,15 @@
// RUN: %clang_cc1 -std=c++23 -verify=cxx23,nontemplate -fsyntax-only -Wc++26-extensions %s
void decompose_array() {
int arr[4] = {1, 2, 3, 6};
constexpr int arr[4] = {1, 2, 3, 6};
// cxx26-warning@+3 {{structured binding packs are incompatible with C++ standards before C++2c}}
// cxx23-warning@+2 {{structured binding packs are a C++2c extension}}
// nontemplate-error@+1 {{pack declaration outside of template}}
auto [x, ...rest, y] = arr;
// cxx26-warning@+4 {{structured binding packs are incompatible with C++ standards before C++2c}}
// cxx23-warning@+3 {{structured binding packs are a C++2c extension}}
// nontemplate-error@+2 {{decomposition declaration cannot be declared 'constexpr'}}
// nontemplate-error@+1 {{pack declaration outside of template}}
constexpr auto [x_c, ...rest_c, y_c] = arr;
}