Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s |
Fariborz Jahanian | eb96e12 | 2009-07-09 19:59:47 +0000 | [diff] [blame] | 2 | |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 3 | struct BB {}; |
Fariborz Jahanian | eb96e12 | 2009-07-09 19:59:47 +0000 | [diff] [blame] | 4 | |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 5 | struct BB1 {}; |
Fariborz Jahanian | eb96e12 | 2009-07-09 19:59:47 +0000 | [diff] [blame] | 6 | |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 7 | class complex : public BB, BB1 { |
Fariborz Jahanian | eb96e12 | 2009-07-09 19:59:47 +0000 | [diff] [blame] | 8 | public: |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 9 | complex() |
| 10 | : s2(1), // expected-warning {{field 's2' will be initialized after field 's1'}} |
| 11 | s1(1), |
| 12 | s3(3), // expected-warning {{field 's3' will be initialized after base 'BB1'}} |
| 13 | BB1(), // expected-warning {{base class 'BB1' will be initialized after base 'BB'}} |
| 14 | BB() |
| 15 | {} |
Fariborz Jahanian | eb96e12 | 2009-07-09 19:59:47 +0000 | [diff] [blame] | 16 | int s1; |
| 17 | int s2; |
| 18 | int s3; |
| 19 | }; |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | // testing virtual bases. |
| 23 | |
| 24 | |
| 25 | struct V { |
| 26 | V(); |
| 27 | }; |
| 28 | |
| 29 | struct A : public virtual V { |
| 30 | A(); |
| 31 | }; |
| 32 | |
| 33 | struct B : public virtual V { |
| 34 | B(); |
| 35 | }; |
| 36 | |
| 37 | struct Diamond : public A, public B { |
| 38 | Diamond() : A(), B() {} |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | struct C : public A, public B, private virtual V { |
| 43 | C() { } |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | struct D : public A, public B { |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 48 | D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | |
| 52 | struct E : public A, public B, private virtual V { |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 53 | E() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | |
| 57 | struct A1 { |
| 58 | A1(); |
| 59 | }; |
| 60 | |
| 61 | struct B1 { |
| 62 | B1(); |
| 63 | }; |
| 64 | |
| 65 | struct F : public A1, public B1, private virtual V { |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 66 | F() : A1(), V() { } // expected-warning {{base class 'A1' will be initialized after base 'V'}} |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct X : public virtual A, virtual V, public virtual B { |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 70 | X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}} |
Fariborz Jahanian | 40c072f | 2009-07-10 20:13:23 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Eli Friedman | 6347f42 | 2009-07-21 19:28:10 +0000 | [diff] [blame] | 73 | class Anon { |
| 74 | int c; union {int a,b;}; int d; |
| 75 | Anon() : c(10), b(1), d(2) {} |
| 76 | }; |
| 77 | class Anon2 { |
| 78 | int c; union {int a,b;}; int d; |
| 79 | Anon2() : c(2), |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 80 | d(10), // expected-warning {{field 'd' will be initialized after field 'b'}} |
| 81 | b(1) {} |
Eli Friedman | 6347f42 | 2009-07-21 19:28:10 +0000 | [diff] [blame] | 82 | }; |
| 83 | class Anon3 { |
| 84 | union {int a,b;}; |
| 85 | Anon3() : b(1) {} |
| 86 | }; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 87 | |
| 88 | namespace T1 { |
| 89 | |
| 90 | struct S1 { }; |
| 91 | struct S2: virtual S1 { }; |
| 92 | struct S3 { }; |
| 93 | |
| 94 | struct S4: virtual S3, S2 { |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 95 | S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}} |
| 96 | S3() { }; |
Anders Carlsson | 6f6de73 | 2010-03-29 05:13:12 +0000 | [diff] [blame] | 97 | }; |
| 98 | } |
John McCall | d6ca8da | 2010-04-10 07:37:23 +0000 | [diff] [blame] | 99 | |
| 100 | namespace test2 { |
| 101 | struct Foo { Foo(); }; |
| 102 | class A { |
| 103 | template <class T> A(T *t) : |
| 104 | y(), // expected-warning {{field 'y' will be initialized after field 'x'}} |
| 105 | x() |
| 106 | {} |
| 107 | Foo x; |
| 108 | Foo y; |
| 109 | }; |
| 110 | } |
John McCall | 3c3ccdb | 2010-04-10 09:28:51 +0000 | [diff] [blame] | 111 | |
| 112 | // PR6575: this should not crash |
| 113 | namespace test3 { |
| 114 | struct MyClass { |
| 115 | MyClass() : m_int(0) {} |
| 116 | union { |
| 117 | struct { |
| 118 | int m_int; |
| 119 | }; |
| 120 | }; |
| 121 | }; |
| 122 | } |
Douglas Gregor | fe2d379 | 2010-05-20 23:49:34 +0000 | [diff] [blame] | 123 | |
| 124 | namespace PR7179 { |
| 125 | struct X |
| 126 | { |
| 127 | struct Y |
| 128 | { |
| 129 | template <class T> Y(T x) : X(x) { } |
| 130 | }; |
| 131 | }; |
| 132 | } |