empty-class-layout.cpp revision dfde681bddd525fd8dcebc98865ff74682d8b833
1// RUN: clang-cc -triple x86_64-unknown-unknown %s -fsyntax-only -verify 2 3#define SA(n, p) int a##n[(p) ? 1 : -1] 4 5struct A { int a; }; 6SA(0, sizeof(A) == 4); 7 8struct B { }; 9SA(1, sizeof(B) == 1); 10 11struct C : A, B { }; 12SA(2, sizeof(C) == 4); 13 14struct D { }; 15struct E : D { }; 16struct F : E { }; 17 18struct G : E, F { }; 19SA(3, sizeof(G) == 2); 20 21struct Empty { Empty(); }; 22 23struct I : Empty { 24 Empty e; 25}; 26SA(4, sizeof(I) == 2); 27 28struct J : Empty { 29 Empty e[2]; 30}; 31SA(5, sizeof(J) == 3); 32 33template<int N> struct Derived : Empty, Derived<N - 1> { 34}; 35template<> struct Derived<0> : Empty { }; 36 37struct S1 : virtual Derived<10> { 38 Empty e; 39}; 40SA(6, sizeof(S1) == 24); 41 42struct S2 : virtual Derived<10> { 43 Empty e[2]; 44}; 45SA(7, sizeof(S2) == 24); 46 47struct S3 { 48 Empty e; 49}; 50 51struct S4 : Empty, S3 { 52}; 53SA(8, sizeof(S4) == 2); 54 55struct S5 : S3, Empty {}; 56SA(9, sizeof(S5) == 2); 57 58struct S6 : S5 { }; 59SA(10, sizeof(S6) == 2); 60 61struct S7 : Empty { 62 void *v; 63}; 64SA(11, sizeof(S7) == 8); 65 66struct S8 : Empty, A { 67}; 68SA(12, sizeof(S8) == 4); 69