1 // RUN: %clang_cc1  -fsyntax-only -Wreorder -verify %s
2 
3 struct BB {};
4 
5 struct BB1 {};
6 
7 class complex : public BB, BB1 {
8 public:
complex()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 
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 {
DiamondDiamond38   Diamond() : A(), B() {}
39 };
40 
41 
42 struct C : public A, public B, private virtual V {
CC43   C() { }
44 };
45 
46 
47 struct D : public A, public B {
DD48   D()  : A(), V() {   } // expected-warning {{base class 'A' will be initialized after base 'V'}}
49 };
50 
51 
52 struct E : public A, public B, private virtual V {
EE53   E()  : A(), V() {  } // expected-warning {{base class 'A' will be initialized after base 'V'}}
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 {
FF66   F()  : A1(), V() {  } // expected-warning {{base class 'A1' will be initialized after base 'V'}}
67 };
68 
69 struct X : public virtual A, virtual V, public virtual B {
XX70   X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}}
71 };
72 
73 class Anon {
74   int c; union {int a,b;}; int d;
Anon()75   Anon() : c(10), b(1), d(2) {}
76 };
77 class Anon2 {
78   int c; union {int a,b;}; int d;
Anon2()79   Anon2() : c(2),
80             d(10), // expected-warning {{field 'd' will be initialized after field 'b'}}
81             b(1) {}
82 };
83 class Anon3 {
84   union {int a,b;};
Anon3()85   Anon3() : b(1) {}
86 };
87 
88 namespace T1 {
89 
90 struct S1 { };
91 struct S2: virtual S1 { };
92 struct S3 { };
93 
94 struct S4: virtual S3, S2 {
S4T1::S495   S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}}
96     S3() { };
97 };
98 }
99 
100 namespace test2 {
101   struct Foo { Foo(); };
102   class A {
A(T * t)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
113 namespace test3 {
114   struct MyClass {
MyClasstest3::MyClass115     MyClass() : m_int(0) {}
116     union {
117       struct {
118         int m_int;
119       };
120     };
121   };
122 }
123 
124 namespace PR7179 {
125   struct X
126   {
127     struct Y
128     {
YPR7179::X::Y129       template <class T> Y(T x) : X(x) { }
130     };
131   };
132 }
133 
134 namespace test3 {
135   struct foo {
136     struct {
137       int a;
138       int b;
139     };
footest3::foo140     foo() : b(), a() { // expected-warning {{field 'b' will be initialized after field 'a'}}
141     }
142   };
143 }
144