1 // RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s
3 using size_t = decltype(sizeof(0));
5 struct complex_double
{
10 template <typename T
, size_t ABI
, size_t Preferred
>
11 struct check_alignment
{
15 static_assert(__alignof__(value
) == Preferred
, "__alignof__(value) != Preferred");
16 static_assert(__alignof__(type
) == Preferred
, "__alignof__(type) != Preferred");
17 static_assert(alignof(type
) == ABI
, "alignof(type) != ABI");
21 template struct check_alignment
<double, 4, 8>;
22 template struct check_alignment
<long long, 4, 8>;
23 template struct check_alignment
<unsigned long long, 4, 8>;
24 template struct check_alignment
<complex_double
, 4, 4>;
27 struct __attribute__((packed
))
31 template struct check_alignment
<packed_struct
, 1, 1>;
32 static_assert(__alignof__(g_packedstruct
.a
) == 1, "__alignof__(packed_struct.member) != 1");
34 template struct check_alignment
<double[3], 4, 8>;
36 enum big_enum
{ x
= 18446744073709551615ULL };
37 template struct check_alignment
<big_enum
, 4, 8>;
41 #define ALIGNED(x) __attribute__((aligned(x)))
43 typedef ALIGNED(2) struct {
45 } aligned_before_struct
;
47 static_assert(sizeof(aligned_before_struct
) == 3, "");
48 static_assert(sizeof(aligned_before_struct
[1]) == 4, ""); // expected-error {{size of array element}}
49 static_assert(sizeof(aligned_before_struct
[2]) == 6, ""); // expected-error {{size of array element}}
50 static_assert(sizeof(aligned_before_struct
[2][1]) == 8, ""); // expected-error {{size of array element}}
51 static_assert(sizeof(aligned_before_struct
[1][2]) == 6, ""); // expected-error {{size of array element}}
53 typedef struct ALIGNED(2) {
55 } aligned_after_struct
;
57 static_assert(sizeof(aligned_after_struct
) == 4, "");
58 static_assert(sizeof(aligned_after_struct
[1]) == 4, "");
59 static_assert(sizeof(aligned_after_struct
[2]) == 8, "");
60 static_assert(sizeof(aligned_after_struct
[2][1]) == 8, "");
61 static_assert(sizeof(aligned_after_struct
[1][2]) == 8, "");