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