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 namespace Test0 { 6 7 struct A { int a; }; 8 SA(0, sizeof(A) == 4); 9 10 struct B { }; 11 SA(1, sizeof(B) == 1); 12 13 struct C : A, B { }; 14 SA(2, sizeof(C) == 4); 15 16 struct D { }; 17 struct E : D { }; 18 struct F : E { }; 19 20 struct G : E, F { }; 21 SA(3, sizeof(G) == 2); 22 23 struct Empty { Empty(); }; 24 25 struct I : Empty { 26 Empty e; 27 }; 28 SA(4, sizeof(I) == 2); 29 30 struct J : Empty { 31 Empty e[2]; 32 }; 33 SA(5, sizeof(J) == 3); 34 35 template<int N> struct Derived : Empty, Derived<N - 1> { 36 }; 37 template<> struct Derived<0> : Empty { }; 38 39 struct S1 : virtual Derived<10> { 40 Empty e; 41 }; 42 SA(6, sizeof(S1) == 24); 43 44 struct S2 : virtual Derived<10> { 45 Empty e[2]; 46 }; 47 SA(7, sizeof(S2) == 24); 48 49 struct S3 { 50 Empty e; 51 }; 52 53 struct S4 : Empty, S3 { 54 }; 55 SA(8, sizeof(S4) == 2); 56 57 struct S5 : S3, Empty {}; 58 SA(9, sizeof(S5) == 2); 59 60 struct S6 : S5 { }; 61 SA(10, sizeof(S6) == 2); 62 63 struct S7 : Empty { 64 void *v; 65 }; 66 SA(11, sizeof(S7) == 8); 67 68 struct S8 : Empty, A { 69 }; 70 SA(12, sizeof(S8) == 4); 71 72 } 73 74 namespace Test1 { 75 76 // Test that we don't try to place both A subobjects at offset 0. 77 struct A { }; 78 class B { virtual void f(); }; 79 class C : A, virtual B { }; 80 struct D : virtual C { }; 81 struct E : virtual A { }; 82 class F : D, E { }; 83 84 SA(0, sizeof(F) == 24); 85 86 } 87 88 namespace Test2 { 89 90 // Test that B::a isn't laid out at offset 0. 91 struct Empty { }; 92 struct A : Empty { }; 93 struct B : Empty { 94 A a; 95 }; 96 97 SA(0, sizeof(B) == 2); 98 99 } 100 101 namespace Test3 { 102 103 // Test that B::a isn't laid out at offset 0. 104 struct Empty { }; 105 struct A { Empty e; }; 106 struct B : Empty { 107 A a; 108 }; 109 110 SA(0, sizeof(B) == 2); 111 112 } 113