1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify -std=c++17 -Wno-bitfield-width %s
2 // expected-no-diagnostics
4 static_assert(__has_unique_object_representations(_BitInt(8)));
5 static_assert(__has_unique_object_representations(unsigned _BitInt(8)));
6 static_assert(__has_unique_object_representations(_BitInt(sizeof(int) * 8u)));
7 // sizeof(_BitInt(24)) may be 4 to align it to the next greater integer type, in which case it would have 8 padding bits.
8 static_assert(__has_unique_object_representations(_BitInt(24)) == (sizeof(_BitInt(24)) == 3));
10 static_assert(!__has_unique_object_representations(_BitInt(7)));
11 static_assert(!__has_unique_object_representations(unsigned _BitInt(7)));
12 static_assert(!__has_unique_object_representations(_BitInt(2)));
13 static_assert(!__has_unique_object_representations(unsigned _BitInt(1)));
16 constexpr bool check() {
17 if constexpr (N
<= __BITINT_MAXWIDTH__
) {
18 static_assert(__has_unique_object_representations(_BitInt(N
)) == (sizeof(_BitInt(N
)) * 8u == N
));
19 static_assert(__has_unique_object_representations(unsigned _BitInt(N
)) == (sizeof(unsigned _BitInt(N
)) * 8u == N
));
24 template <unsigned... N
>
25 constexpr bool do_check
= (check
<N
>() && ...);
27 static_assert(do_check
<2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18>);
28 static_assert(do_check
<15, 16, 17, 23, 24, 25, 31, 32, 33>);
29 static_assert(do_check
<39, 40, 41, 47, 48, 49>);
30 static_assert(do_check
<127, 128, 129, 255, 256, 257, 383, 384, 385>);
35 static constexpr bool check() {
36 return __has_unique_object_representations(in_struct
<N
>) == __has_unique_object_representations(_BitInt(N
));
40 static_assert(in_struct
<8>::check());
41 static_assert(in_struct
<7>::check());
45 unsigned _BitInt(1) y
: 1;
48 static_assert(__has_unique_object_representations(bit_fields_1
) == (sizeof(bit_fields_1
) == 1));
54 static_assert(!__has_unique_object_representations(bit_fields_2
));
60 static_assert(__has_unique_object_representations(bit_fields_3
) == (sizeof(bit_fields_3
) == 1));
62 #if __BITINT_MAXWIDTH__ >= 129
67 static_assert(__has_unique_object_representations(bit_fields_4
) == (sizeof(bit_fields_4
) == 128 / 8));
74 static_assert(!__has_unique_object_representations(bit_fields_5
));
81 struct int_ref_member
{
85 static_assert(__has_unique_object_representations(ref_member
<7>) == __has_unique_object_representations(ref_member
<8>));
86 static_assert(__has_unique_object_representations(ref_member
<8>) == __has_unique_object_representations(int_ref_member
));