Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / warn-reorder-ctor-initialization.cpp
blob06133389459782828519391bb45870a977bbba43
1 // RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s
3 struct BB {};
5 struct BB1 {};
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 };
21 // testing virtual bases.
24 struct V {
25 V();
28 struct A : public virtual V {
29 A();
32 struct B : public virtual V {
33 B();
36 struct Diamond : public A, public B {
37 Diamond() : A(), B() {}
41 struct C : public A, public B, private virtual V {
42 C() { }
46 struct D : public A, public B {
47 D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}
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'}}
56 struct A1 {
57 A1();
60 struct B1 {
61 B1();
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'}}
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'}}
72 class Anon {
73 int c; union {int a,b;}; int d;
74 Anon() : c(10), b(1), d(2) {}
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) {}
82 class Anon3 {
83 union {int a,b;};
84 Anon3() : b(1) {}
87 namespace T1 {
89 struct S1 { };
90 struct S2: virtual S1 { };
91 struct S3 { };
93 struct S4: virtual S3, S2 {
94 S4() : S2(), // expected-warning {{base class 'S2' will be initialized after base 'S3'}}
95 S3() { };
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'}}
106 Foo x;
107 Foo y;
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;
123 namespace PR7179 {
124 struct X
126 struct Y
128 template <class T> Y(T x) : X(x) { }
133 namespace test3 {
134 struct foo {
135 struct {
136 int a;
137 int b;
139 foo() : b(), a() { // expected-warning {{field 'b' will be initialized after field 'a'}}