[OpenACC] Enable 'attach' clause for combined constructs
[llvm-project.git] / clang / test / SemaCXX / has_unique_object_reps_bitint.cpp
blob83190d006030e30ffe6d5185a59fe985fa7c46ee
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)));
15 template <unsigned N>
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));
21 return true;
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>);
32 template <unsigned N>
33 struct in_struct {
34 _BitInt(N) x;
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());
43 struct bit_fields_1 {
44 _BitInt(7) x : 7;
45 unsigned _BitInt(1) y : 1;
48 static_assert(__has_unique_object_representations(bit_fields_1) == (sizeof(bit_fields_1) == 1));
50 struct bit_fields_2 {
51 _BitInt(8) x : 7;
54 static_assert(!__has_unique_object_representations(bit_fields_2));
56 struct bit_fields_3 {
57 _BitInt(15) x : 8;
60 static_assert(__has_unique_object_representations(bit_fields_3) == (sizeof(bit_fields_3) == 1));
62 #if __BITINT_MAXWIDTH__ >= 129
63 struct bit_fields_4 {
64 _BitInt(129) x : 128;
67 static_assert(__has_unique_object_representations(bit_fields_4) == (sizeof(bit_fields_4) == 128 / 8));
68 #endif
70 struct bit_fields_5 {
71 _BitInt(2) x : 8;
74 static_assert(!__has_unique_object_representations(bit_fields_5));
76 template <unsigned N>
77 struct ref_member {
78 _BitInt(N) & x;
81 struct int_ref_member {
82 int &x;
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));