1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc struct BB {}; 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc struct BB1 {}; 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc class complex : public BB, BB1 { 8*f4a2713aSLionel Sambuc public: complex()9*f4a2713aSLionel Sambuc complex() 10*f4a2713aSLionel Sambuc : s2(1), // expected-warning {{field 's2' will be initialized after field 's1'}} 11*f4a2713aSLionel Sambuc s1(1), 12*f4a2713aSLionel Sambuc s3(3), // expected-warning {{field 's3' will be initialized after base 'BB1'}} 13*f4a2713aSLionel Sambuc BB1(), // expected-warning {{base class 'BB1' will be initialized after base 'BB'}} 14*f4a2713aSLionel Sambuc BB() 15*f4a2713aSLionel Sambuc {} 16*f4a2713aSLionel Sambuc int s1; 17*f4a2713aSLionel Sambuc int s2; 18*f4a2713aSLionel Sambuc int s3; 19*f4a2713aSLionel Sambuc }; 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc // testing virtual bases. 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc struct V { 26*f4a2713aSLionel Sambuc V(); 27*f4a2713aSLionel Sambuc }; 28*f4a2713aSLionel Sambuc 29*f4a2713aSLionel Sambuc struct A : public virtual V { 30*f4a2713aSLionel Sambuc A(); 31*f4a2713aSLionel Sambuc }; 32*f4a2713aSLionel Sambuc 33*f4a2713aSLionel Sambuc struct B : public virtual V { 34*f4a2713aSLionel Sambuc B(); 35*f4a2713aSLionel Sambuc }; 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc struct Diamond : public A, public B { DiamondDiamond38*f4a2713aSLionel Sambuc Diamond() : A(), B() {} 39*f4a2713aSLionel Sambuc }; 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc struct C : public A, public B, private virtual V { CC43*f4a2713aSLionel Sambuc C() { } 44*f4a2713aSLionel Sambuc }; 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc struct D : public A, public B { DD48*f4a2713aSLionel Sambuc D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} 49*f4a2713aSLionel Sambuc }; 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc 52*f4a2713aSLionel Sambuc struct E : public A, public B, private virtual V { EE53*f4a2713aSLionel Sambuc E() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}} 54*f4a2713aSLionel Sambuc }; 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc struct A1 { 58*f4a2713aSLionel Sambuc A1(); 59*f4a2713aSLionel Sambuc }; 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc struct B1 { 62*f4a2713aSLionel Sambuc B1(); 63*f4a2713aSLionel Sambuc }; 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc struct F : public A1, public B1, private virtual V { FF66*f4a2713aSLionel Sambuc F() : A1(), V() { } // expected-warning {{base class 'A1' will be initialized after base 'V'}} 67*f4a2713aSLionel Sambuc }; 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambuc struct X : public virtual A, virtual V, public virtual B { XX70*f4a2713aSLionel Sambuc X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}} 71*f4a2713aSLionel Sambuc }; 72*f4a2713aSLionel Sambuc 73*f4a2713aSLionel Sambuc class Anon { 74*f4a2713aSLionel Sambuc int c; union {int a,b;}; int d; Anon()75*f4a2713aSLionel Sambuc Anon() : c(10), b(1), d(2) {} 76*f4a2713aSLionel Sambuc }; 77*f4a2713aSLionel Sambuc class Anon2 { 78*f4a2713aSLionel Sambuc int c; union {int a,b;}; int d; Anon2()79*f4a2713aSLionel Sambuc Anon2() : c(2), 80*f4a2713aSLionel Sambuc d(10), // expected-warning {{field 'd' will be initialized after field 'b'}} 81*f4a2713aSLionel Sambuc b(1) {} 82*f4a2713aSLionel Sambuc }; 83*f4a2713aSLionel Sambuc class Anon3 { 84*f4a2713aSLionel Sambuc union {int a,b;}; Anon3()85*f4a2713aSLionel Sambuc Anon3() : b(1) {} 86*f4a2713aSLionel Sambuc }; 87*f4a2713aSLionel Sambuc 88*f4a2713aSLionel Sambuc namespace T1 { 89*f4a2713aSLionel Sambuc 90*f4a2713aSLionel Sambuc struct S1 { }; 91*f4a2713aSLionel Sambuc struct S2: virtual S1 { }; 92*f4a2713aSLionel Sambuc struct S3 { }; 93*f4a2713aSLionel Sambuc 94*f4a2713aSLionel Sambuc struct S4: virtual S3, S2 { S4T1::S495*f4a2713aSLionel Sambuc S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}} 96*f4a2713aSLionel Sambuc S3() { }; 97*f4a2713aSLionel Sambuc }; 98*f4a2713aSLionel Sambuc } 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambuc namespace test2 { 101*f4a2713aSLionel Sambuc struct Foo { Foo(); }; 102*f4a2713aSLionel Sambuc class A { A(T * t)103*f4a2713aSLionel Sambuc template <class T> A(T *t) : 104*f4a2713aSLionel Sambuc y(), // expected-warning {{field 'y' will be initialized after field 'x'}} 105*f4a2713aSLionel Sambuc x() 106*f4a2713aSLionel Sambuc {} 107*f4a2713aSLionel Sambuc Foo x; 108*f4a2713aSLionel Sambuc Foo y; 109*f4a2713aSLionel Sambuc }; 110*f4a2713aSLionel Sambuc } 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc // PR6575: this should not crash 113*f4a2713aSLionel Sambuc namespace test3 { 114*f4a2713aSLionel Sambuc struct MyClass { MyClasstest3::MyClass115*f4a2713aSLionel Sambuc MyClass() : m_int(0) {} 116*f4a2713aSLionel Sambuc union { 117*f4a2713aSLionel Sambuc struct { 118*f4a2713aSLionel Sambuc int m_int; 119*f4a2713aSLionel Sambuc }; 120*f4a2713aSLionel Sambuc }; 121*f4a2713aSLionel Sambuc }; 122*f4a2713aSLionel Sambuc } 123*f4a2713aSLionel Sambuc 124*f4a2713aSLionel Sambuc namespace PR7179 { 125*f4a2713aSLionel Sambuc struct X 126*f4a2713aSLionel Sambuc { 127*f4a2713aSLionel Sambuc struct Y 128*f4a2713aSLionel Sambuc { YPR7179::X::Y129*f4a2713aSLionel Sambuc template <class T> Y(T x) : X(x) { } 130*f4a2713aSLionel Sambuc }; 131*f4a2713aSLionel Sambuc }; 132*f4a2713aSLionel Sambuc } 133*f4a2713aSLionel Sambuc 134*f4a2713aSLionel Sambuc namespace test3 { 135*f4a2713aSLionel Sambuc struct foo { 136*f4a2713aSLionel Sambuc struct { 137*f4a2713aSLionel Sambuc int a; 138*f4a2713aSLionel Sambuc int b; 139*f4a2713aSLionel Sambuc }; footest3::foo140*f4a2713aSLionel Sambuc foo() : b(), a() { // expected-warning {{field 'b' will be initialized after field 'a'}} 141*f4a2713aSLionel Sambuc } 142*f4a2713aSLionel Sambuc }; 143*f4a2713aSLionel Sambuc } 144