1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 2 // expected-no-diagnostics 3 4 #define SA(n, p) int a##n[(p) ? 1 : -1] 5 6 struct A { 7 int a; 8 char b; 9 }; 10 11 SA(0, sizeof(A) == 8); 12 13 struct B : A { 14 char c; 15 }; 16 17 SA(1, sizeof(B) == 12); 18 19 struct C { 20 // Make fields private so C won't be a POD type. 21 private: 22 int a; 23 char b; 24 }; 25 26 SA(2, sizeof(C) == 8); 27 28 struct D : C { 29 char c; 30 }; 31 32 SA(3, sizeof(D) == 8); 33 34 struct __attribute__((packed)) E { 35 char b; 36 int a; 37 }; 38 39 SA(4, sizeof(E) == 5); 40 41 struct __attribute__((packed)) F : E { 42 char d; 43 }; 44 45 SA(5, sizeof(F) == 6); 46 47 struct G { G(); }; 48 struct H : G { }; 49 50 SA(6, sizeof(H) == 1); 51 52 struct I { 53 char b; 54 int a; 55 } __attribute__((packed)); 56 57 SA(6_1, sizeof(I) == 5); 58 59 // PR5580 60 namespace PR5580 { 61 62 class A { bool iv0 : 1; }; 63 SA(7, sizeof(A) == 1); 64 65 class B : A { bool iv0 : 1; }; 66 SA(8, sizeof(B) == 2); 67 68 struct C { bool iv0 : 1; }; 69 SA(9, sizeof(C) == 1); 70 71 struct D : C { bool iv0 : 1; }; 72 SA(10, sizeof(D) == 2); 73 74 } 75 76 namespace Test1 { 77 78 // Test that we don't assert on this hierarchy. 79 struct A { }; 80 struct B : A { virtual void b(); }; 81 class C : virtual A { int c; }; 82 struct D : virtual B { }; 83 struct E : C, virtual D { }; 84 class F : virtual E { }; 85 struct G : virtual E, F { }; 86 87 SA(0, sizeof(G) == 24); 88 89 } 90 91 namespace Test2 { 92 93 // Test that this somewhat complex class structure is laid out correctly. 94 struct A { }; 95 struct B : A { virtual void b(); }; 96 struct C : virtual B { }; 97 struct D : virtual A { }; 98 struct E : virtual B, D { }; 99 struct F : E, virtual C { }; 100 struct G : virtual F, A { }; 101 struct H { G g; }; 102 103 SA(0, sizeof(H) == 24); 104 105 } 106