• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { A a; };
107 SA(0, sizeof(B) == 2);
108 
109 }
110 
111 namespace Test4 {
112 
113 // Test that C::Empty isn't laid out at offset 0.
114 struct Empty { };
115 struct A : Empty { };
116 struct B { A a; };
117 struct C : B, Empty { };
118 SA(0, sizeof(C) == 2);
119 
120 }
121 
122 namespace Test5 {
123 
124 // Test that B::Empty isn't laid out at offset 0.
125 struct Empty { };
126 struct Field : virtual Empty { };
127 struct A {
128   Field f;
129 };
130 struct B : A, Empty { };
131 SA(0, sizeof(B) == 16);
132 
133 }
134 
135 namespace Test6 {
136 
137 // Test that B::A isn't laid out at offset 0.
138 struct Empty { };
139 struct Field : virtual Empty { };
140 struct A {
141   Field f;
142 };
143 struct B : Empty, A { };
144 SA(0, sizeof(B) == 16);
145 
146 }
147 
148 namespace Test7 {
149   // Make sure we reserve enough space for both bases; PR11745.
150   struct Empty { };
151   struct Base1 : Empty { };
152   struct Base2 : Empty { };
153   struct Test : Base1, Base2 {
154     char c;
155   };
156   SA(0, sizeof(Test) == 2);
157 }
158