1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -Wno-inaccessible-base
2 // expected-no-diagnostics
4 #define SA(n, p) int a##n[(p) ? 1 : -1]
12 SA(1, sizeof(B
) == 1);
15 SA(2, sizeof(C
) == 4);
22 SA(3, sizeof(G
) == 2);
24 struct Empty
{ Empty(); };
29 SA(4, sizeof(I
) == 2);
34 SA(5, sizeof(J
) == 3);
36 template<int N
> struct Derived
: Empty
, Derived
<N
- 1> {
38 template<> struct Derived
<0> : Empty
{ };
40 struct S1
: virtual Derived
<10> {
43 SA(6, sizeof(S1
) == 24);
45 struct S2
: virtual Derived
<10> {
48 SA(7, sizeof(S2
) == 24);
54 struct S4
: Empty
, S3
{
56 SA(8, sizeof(S4
) == 2);
58 struct S5
: S3
, Empty
{};
59 SA(9, sizeof(S5
) == 2);
62 SA(10, sizeof(S6
) == 2);
67 SA(11, sizeof(S7
) == 8);
69 struct S8
: Empty
, A
{
71 SA(12, sizeof(S8
) == 4);
77 // Test that we don't try to place both A subobjects at offset 0.
79 class B
{ virtual void f(); };
80 class C
: A
, virtual B
{ };
81 struct D
: virtual C
{ };
82 struct E
: virtual A
{ };
85 SA(0, sizeof(F
) == 24);
91 // Test that B::a isn't laid out at offset 0.
98 SA(0, sizeof(B
) == 2);
104 // Test that B::a isn't laid out at offset 0.
106 struct A
{ Empty e
; };
107 struct B
: Empty
{ A a
; };
108 SA(0, sizeof(B
) == 2);
114 // Test that C::Empty isn't laid out at offset 0.
116 struct A
: Empty
{ };
118 struct C
: B
, Empty
{ };
119 SA(0, sizeof(C
) == 2);
125 // Test that B::Empty isn't laid out at offset 0.
127 struct Field
: virtual Empty
{ };
131 struct B
: A
, Empty
{ };
132 SA(0, sizeof(B
) == 16);
138 // Test that B::A isn't laid out at offset 0.
140 struct Field
: virtual Empty
{ };
144 struct B
: Empty
, A
{ };
145 SA(0, sizeof(B
) == 16);
150 // Make sure we reserve enough space for both bases; PR11745.
152 struct Base1
: Empty
{ };
153 struct Base2
: Empty
{ };
154 struct Test
: Base1
, Base2
{
157 SA(0, sizeof(Test
) == 2);
161 // Test that type sugar doesn't make us incorrectly determine the size of an
162 // array of empty classes.
165 struct Empties
: Empty1
, Empty2
{};
166 typedef Empty1 Sugar
[4];
167 struct A
: Empty2
, Empties
{
168 // This must go at offset 2, because if it were at offset 0,
169 // V[0][1] would overlap Empties::Empty1.
172 SA(0, sizeof(A
) == 6);