1 // RUN: %clang_cc1 -std=c++11 -triple i386-apple-darwin9 -fsyntax-only -verify %s 2 // expected-no-diagnostics 3 4 using size_t = decltype(sizeof(0)); 5 6 struct complex_double { 7 double real; 8 double imag; 9 }; 10 11 template <typename T, size_t ABI, size_t Preferred> 12 struct check_alignment { 13 using type = T; 14 static type value; 15 16 static_assert(__alignof__(value) == Preferred, "__alignof__(value) != Preferred"); 17 static_assert(__alignof__(type) == Preferred, "__alignof__(type) != Preferred"); 18 static_assert(alignof(type) == ABI, "alignof(type) != ABI"); 19 }; 20 21 // PR3433 22 template struct check_alignment<double, 4, 8>; 23 template struct check_alignment<long long, 4, 8>; 24 template struct check_alignment<unsigned long long, 4, 8>; 25 template struct check_alignment<complex_double, 4, 4>; 26 27 // PR6362 28 struct __attribute__((packed)) 29 packed_struct { 30 unsigned int a; 31 } g_packedstruct; 32 template struct check_alignment<packed_struct, 1, 1>; 33 static_assert(__alignof__(g_packedstruct.a) == 1, "__alignof__(packed_struct.member) != 1"); 34 35 template struct check_alignment<double[3], 4, 8>; 36 37 enum big_enum { x = 18446744073709551615ULL }; 38 template struct check_alignment<big_enum, 4, 8>; 39 40 // PR5637 41 42 #define ALIGNED(x) __attribute__((aligned(x))) 43 44 typedef ALIGNED(2) struct { 45 char a[3]; 46 } aligned_before_struct; 47 48 static_assert(sizeof(aligned_before_struct) == 3, ""); 49 static_assert(sizeof(aligned_before_struct[1]) == 4, ""); 50 static_assert(sizeof(aligned_before_struct[2]) == 6, ""); 51 static_assert(sizeof(aligned_before_struct[2][1]) == 8, ""); 52 static_assert(sizeof(aligned_before_struct[1][2]) == 6, ""); 53 54 typedef struct ALIGNED(2) { 55 char a[3]; 56 } aligned_after_struct; 57 58 static_assert(sizeof(aligned_after_struct) == 4, ""); 59 static_assert(sizeof(aligned_after_struct[1]) == 4, ""); 60 static_assert(sizeof(aligned_after_struct[2]) == 8, ""); 61 static_assert(sizeof(aligned_after_struct[2][1]) == 8, ""); 62 static_assert(sizeof(aligned_after_struct[1][2]) == 8, ""); 63