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