Skip to content

Commit d496c54

Browse files
committed
[Clang][P1061] Add bit-field and pack indexing tests
1 parent 0b83b99 commit d496c54

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,8 @@ bool Sema::CheckParameterPacksForExpansion(
802802
CurrentInstantiationScope->findInstantiationOf(ND);
803803
Decl *B = cast<Decl *>(*Instantiation);
804804
Expr *BindingExpr = cast<BindingDecl>(B)->getBinding();
805-
ResolvedPack = dyn_cast<ResolvedUnexpandedPackExpr>(BindingExpr);
805+
ResolvedPack =
806+
dyn_cast_if_present<ResolvedUnexpandedPackExpr>(BindingExpr);
806807
if (!ResolvedPack) {
807808
ShouldExpand = false;
808809
continue;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ template <typename T>
6060
void decompose_struct() {
6161
T obj{1, 2, 3, 6};
6262
auto [x, ...rest, y] = obj;
63+
64+
auto [...empty] = type_<int>{};
65+
static_assert(sizeof...(empty) == 0);
6366
}
6467

6568
template <typename T>
@@ -88,9 +91,27 @@ struct S {
8891
};
8992
};
9093

94+
struct bit_fields {
95+
int a : 4 {1};
96+
int b : 4 {2};
97+
int c : 4 {3};
98+
int d : 4 {4};
99+
};
100+
101+
template <typename T>
102+
void decompose_bit_field() {
103+
auto [...x] = T{};
104+
static_assert(sizeof...(x) == 4);
105+
int a = x...[0];
106+
int b = x...[1];
107+
int c = x...[2];
108+
int d = x...[3];
109+
}
110+
91111
int main() {
92112
decompose_array<int>();
93113
decompose_tuple<fake_tuple>();
94114
decompose_struct<my_struct>();
95115
S<1, 2, 3, 4>::N<5, 6>().foo();
116+
decompose_bit_field<bit_fields>();
96117
}

0 commit comments

Comments
 (0)