Skip to content

Commit 0b83b99

Browse files
committed
[Clang][P1061] Fix crash (part 2)
1 parent dda9d89 commit 0b83b99

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,14 +1009,16 @@ struct BindingInitWalker {
10091009
using BindingItrTy = typename ArrayRef<BindingDecl *>::iterator;
10101010
using PackExprItrTy = typename MutableArrayRef<Expr *>::iterator;
10111011
Sema &SemaRef;
1012+
DecompositionDecl *DecompDecl;
10121013
ArrayRef<BindingDecl *> Bindings;
10131014
ResolvedUnexpandedPackExpr *PackExpr = nullptr;
10141015
MutableArrayRef<Expr *> PackExprNodes;
10151016
BindingItrTy BindingItr;
10161017
PackExprItrTy PackExprItr;
10171018

1018-
BindingInitWalker(Sema &S, ArrayRef<BindingDecl *> Bs)
1019-
: SemaRef(S), Bindings(Bs), BindingItr(Bindings.begin()) {}
1019+
BindingInitWalker(Sema &S, DecompositionDecl *DD, ArrayRef<BindingDecl *> Bs)
1020+
: SemaRef(S), DecompDecl(DD), Bindings(Bs), BindingItr(Bindings.begin()) {
1021+
}
10201022

10211023
BindingDecl *get() { return *BindingItr; }
10221024

@@ -1037,7 +1039,7 @@ struct BindingInitWalker {
10371039
B->getLocation(), B->getIdentifier(), T);
10381040

10391041
NestedBD->setBinding(T, E);
1040-
NestedBD->setDecomposedDecl(nullptr);
1042+
NestedBD->setDecomposedDecl(DecompDecl);
10411043
auto *DE = SemaRef.BuildDeclRefExpr(NestedBD, T.getNonReferenceType(),
10421044
VK_LValue, B->getLocation());
10431045
*PackExprItr = DE;
@@ -1065,7 +1067,7 @@ static bool checkSimpleDecomposition(
10651067
return true;
10661068
}
10671069

1068-
auto Walker = BindingInitWalker(S, Bindings);
1070+
auto Walker = BindingInitWalker(S, cast<DecompositionDecl>(Src), Bindings);
10691071
for (unsigned I = 0; I < NumElems; I++) {
10701072
BindingDecl *B = Walker.get();
10711073
SourceLocation Loc = B->getLocation();
@@ -1350,7 +1352,7 @@ static bool checkTupleLikeDecomposition(Sema &S,
13501352
}
13511353
}
13521354

1353-
auto Walker = BindingInitWalker(S, Bindings);
1355+
auto Walker = BindingInitWalker(S, cast<DecompositionDecl>(Src), Bindings);
13541356
for (unsigned I = 0; I < NumElems; I++) {
13551357
BindingDecl *B = Walker.get();
13561358
InitializingBinding InitContext(S, B);
@@ -1541,7 +1543,7 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> Bindings,
15411543
return true;
15421544
}
15431545

1544-
auto Walker = BindingInitWalker(S, Bindings);
1546+
auto Walker = BindingInitWalker(S, cast<DecompositionDecl>(Src), Bindings);
15451547

15461548
// all of E's non-static data members shall be [...] well-formed
15471549
// when named as e.name in the context of the structured binding,

clang/test/SemaCXX/cxx2c-binding-pack.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,24 @@ void decompose_array() {
7373
auto [...pack] = arr2;
7474
}
7575

76+
// Test case by Younan Zhang.
77+
template <unsigned... P>
78+
struct S {
79+
template <unsigned... Q>
80+
struct N {
81+
void foo() {
82+
int arr[] = {P..., Q...};
83+
auto [x, y, ...rest] = arr;
84+
[&]() {
85+
static_assert(sizeof...(rest) + 2 == sizeof...(P) + sizeof...(Q));
86+
}();
87+
}
88+
};
89+
};
90+
7691
int main() {
7792
decompose_array<int>();
7893
decompose_tuple<fake_tuple>();
7994
decompose_struct<my_struct>();
95+
S<1, 2, 3, 4>::N<5, 6>().foo();
8096
}

0 commit comments

Comments
 (0)