143 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s2 3struct BB {};4 5struct BB1 {};6 7class complex : public BB, BB1 {8public: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 24struct V { 25 V();26};27 28struct A : public virtual V { 29 A(); 30};31 32struct B : public virtual V {33 B(); 34};35 36struct Diamond : public A, public B {37 Diamond() : A(), B() {}38};39 40 41struct C : public A, public B, private virtual V { 42 C() { }43};44 45 46struct D : public A, public B { 47 D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}48};49 50 51struct 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 56struct A1 { 57 A1(); 58};59 60struct B1 {61 B1();62};63 64struct 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 68struct 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 72class Anon {73 int c; union {int a,b;}; int d;74 Anon() : c(10), b(1), d(2) {}75};76class 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};82class Anon3 {83 union {int a,b;};84 Anon3() : b(1) {}85};86 87namespace T1 {88 89struct S1 { };90struct S2: virtual S1 { };91struct S3 { };92 93struct S4: virtual S3, S2 {94 S4() : S2(), // expected-warning {{base class 'S2' will be initialized after base 'S3'}}95 S3() { };96};97}98 99namespace 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 crash112namespace test3 {113 struct MyClass {114 MyClass() : m_int(0) {}115 union {116 struct {117 int m_int;118 };119 };120 };121}122 123namespace PR7179 {124 struct X125 {126 struct Y127 {128 template <class T> Y(T x) : X(x) { }129 };130 };131}132 133namespace 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}143