1// RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s 2 3struct BB {}; 4 5struct BB1 {}; 6 7class complex : public BB, BB1 { 8public: 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 {} 16 int s1; 17 int s2; 18 int s3; 19}; 20 21 22// testing virtual bases. 23 24 25struct V { 26 V(); 27}; 28 29struct A : public virtual V { 30 A(); 31}; 32 33struct B : public virtual V { 34 B(); 35}; 36 37struct Diamond : public A, public B { 38 Diamond() : A(), B() {} 39}; 40 41 42struct C : public A, public B, private virtual V { 43 C() { } 44}; 45 46 47struct D : public A, public B { 48 D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} 49}; 50 51 52struct E : public A, public B, private virtual V { 53 E() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} 54}; 55 56 57struct A1 { 58 A1(); 59}; 60 61struct B1 { 62 B1(); 63}; 64 65struct F : public A1, public B1, private virtual V { 66 F() : A1(), V() { } // expected-warning {{base class 'A1' will be initialized after base 'V'}} 67}; 68 69struct X : public virtual A, virtual V, public virtual B { 70 X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}} 71}; 72 73class Anon { 74 int c; union {int a,b;}; int d; 75 Anon() : c(10), b(1), d(2) {} 76}; 77class Anon2 { 78 int c; union {int a,b;}; int d; 79 Anon2() : c(2), 80 d(10), // expected-warning {{field 'd' will be initialized after field 'b'}} 81 b(1) {} 82}; 83class Anon3 { 84 union {int a,b;}; 85 Anon3() : b(1) {} 86}; 87 88namespace T1 { 89 90struct S1 { }; 91struct S2: virtual S1 { }; 92struct S3 { }; 93 94struct S4: virtual S3, S2 { 95 S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}} 96 S3() { }; 97}; 98} 99 100namespace 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} 111 112// PR6575: this should not crash 113namespace test3 { 114 struct MyClass { 115 MyClass() : m_int(0) {} 116 union { 117 struct { 118 int m_int; 119 }; 120 }; 121 }; 122} 123 124namespace PR7179 { 125 struct X 126 { 127 struct Y 128 { 129 template <class T> Y(T x) : X(x) { } 130 }; 131 }; 132} 133 134namespace test3 { 135 struct foo { 136 struct { 137 int a; 138 int b; 139 }; 140 foo() : b(), a() { // expected-warning {{field 'b' will be initialized after field 'a'}} 141 } 142 }; 143} 144