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