Debian Codegraph @

clang/test/SemaCXX/warn-reorder-ctor-initialization.cpp

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