blob: 8c254e5515bfca17e59176ef77de74e3a77455f2 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s
Fariborz Jahanianeb96e122009-07-09 19:59:47 +00002
Fariborz Jahanian40c072f2009-07-10 20:13:23 +00003struct BB {};
Fariborz Jahanianeb96e122009-07-09 19:59:47 +00004
Fariborz Jahanian40c072f2009-07-10 20:13:23 +00005struct BB1 {};
Fariborz Jahanianeb96e122009-07-09 19:59:47 +00006
Fariborz Jahanian40c072f2009-07-10 20:13:23 +00007class complex : public BB, BB1 {
Fariborz Jahanianeb96e122009-07-09 19:59:47 +00008public:
John McCalld6ca8da2010-04-10 07:37:23 +00009 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 Jahanianeb96e122009-07-09 19:59:47 +000016 int s1;
17 int s2;
18 int s3;
19};
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000020
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 {
John McCalld6ca8da2010-04-10 07:37:23 +000048 D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000049};
50
51
52struct E : public A, public B, private virtual V {
John McCalld6ca8da2010-04-10 07:37:23 +000053 E() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000054};
55
56
57struct A1 {
58 A1();
59};
60
61struct B1 {
62 B1();
63};
64
65struct F : public A1, public B1, private virtual V {
John McCalld6ca8da2010-04-10 07:37:23 +000066 F() : A1(), V() { } // expected-warning {{base class 'A1' will be initialized after base 'V'}}
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000067};
68
69struct X : public virtual A, virtual V, public virtual B {
John McCalld6ca8da2010-04-10 07:37:23 +000070 X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}}
Fariborz Jahanian40c072f2009-07-10 20:13:23 +000071};
72
Eli Friedman6347f422009-07-21 19:28:10 +000073class 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),
John McCalld6ca8da2010-04-10 07:37:23 +000080 d(10), // expected-warning {{field 'd' will be initialized after field 'b'}}
81 b(1) {}
Eli Friedman6347f422009-07-21 19:28:10 +000082};
83class Anon3 {
84 union {int a,b;};
85 Anon3() : b(1) {}
86};
Anders Carlsson6f6de732010-03-29 05:13:12 +000087
88namespace T1 {
89
90struct S1 { };
91struct S2: virtual S1 { };
92struct S3 { };
93
94struct S4: virtual S3, S2 {
John McCalld6ca8da2010-04-10 07:37:23 +000095 S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}}
96 S3() { };
Anders Carlsson6f6de732010-03-29 05:13:12 +000097};
98}
John McCalld6ca8da2010-04-10 07:37:23 +000099
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}
John McCall3c3ccdb2010-04-10 09:28:51 +0000111
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}
Douglas Gregorfe2d3792010-05-20 23:49:34 +0000123
124namespace PR7179 {
125 struct X
126 {
127 struct Y
128 {
129 template <class T> Y(T x) : X(x) { }
130 };
131 };
132}