2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wreorder -verify %s
|
2009-07-10 03:59:47 +08:00
|
|
|
|
2009-07-11 04:13:23 +08:00
|
|
|
struct BB {};
|
2009-07-10 03:59:47 +08:00
|
|
|
|
2009-07-11 04:13:23 +08:00
|
|
|
struct BB1 {};
|
2009-07-10 03:59:47 +08:00
|
|
|
|
2009-07-11 04:13:23 +08:00
|
|
|
class complex : public BB, BB1 {
|
2009-07-10 03:59:47 +08:00
|
|
|
public:
|
2010-04-10 15:37:23 +08:00
|
|
|
complex()
|
|
|
|
: s2(1), // expected-warning {{field 's2' will be initialized after field 's1'}}
|
|
|
|
s1(1),
|
|
|
|
s3(3), // expected-warning {{field 's3' will be initialized after base 'BB1'}}
|
|
|
|
BB1(), // expected-warning {{base class 'BB1' will be initialized after base 'BB'}}
|
|
|
|
BB()
|
|
|
|
{}
|
2009-07-10 03:59:47 +08:00
|
|
|
int s1;
|
|
|
|
int s2;
|
|
|
|
int s3;
|
|
|
|
};
|
2009-07-11 04:13:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
// testing virtual bases.
|
|
|
|
|
|
|
|
|
|
|
|
struct V {
|
|
|
|
V();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct A : public virtual V {
|
|
|
|
A();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : public virtual V {
|
|
|
|
B();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Diamond : public A, public B {
|
|
|
|
Diamond() : A(), B() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct C : public A, public B, private virtual V {
|
|
|
|
C() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct D : public A, public B {
|
2010-04-10 15:37:23 +08:00
|
|
|
D() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}
|
2009-07-11 04:13:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct E : public A, public B, private virtual V {
|
2010-04-10 15:37:23 +08:00
|
|
|
E() : A(), V() { } // expected-warning {{base class 'A' will be initialized after base 'V'}}
|
2009-07-11 04:13:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct A1 {
|
|
|
|
A1();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B1 {
|
|
|
|
B1();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct F : public A1, public B1, private virtual V {
|
2010-04-10 15:37:23 +08:00
|
|
|
F() : A1(), V() { } // expected-warning {{base class 'A1' will be initialized after base 'V'}}
|
2009-07-11 04:13:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct X : public virtual A, virtual V, public virtual B {
|
2010-04-10 15:37:23 +08:00
|
|
|
X(): A(), V(), B() {} // expected-warning {{base class 'A' will be initialized after base 'V'}}
|
2009-07-11 04:13:23 +08:00
|
|
|
};
|
|
|
|
|
2009-07-22 03:28:10 +08:00
|
|
|
class Anon {
|
|
|
|
int c; union {int a,b;}; int d;
|
|
|
|
Anon() : c(10), b(1), d(2) {}
|
|
|
|
};
|
|
|
|
class Anon2 {
|
|
|
|
int c; union {int a,b;}; int d;
|
|
|
|
Anon2() : c(2),
|
2010-04-10 15:37:23 +08:00
|
|
|
d(10), // expected-warning {{field 'd' will be initialized after field 'b'}}
|
|
|
|
b(1) {}
|
2009-07-22 03:28:10 +08:00
|
|
|
};
|
|
|
|
class Anon3 {
|
|
|
|
union {int a,b;};
|
|
|
|
Anon3() : b(1) {}
|
|
|
|
};
|
2010-03-29 13:13:12 +08:00
|
|
|
|
|
|
|
namespace T1 {
|
|
|
|
|
|
|
|
struct S1 { };
|
|
|
|
struct S2: virtual S1 { };
|
|
|
|
struct S3 { };
|
|
|
|
|
|
|
|
struct S4: virtual S3, S2 {
|
2010-04-10 15:37:23 +08:00
|
|
|
S4() : S2(), // expected-warning {{base class 'T1::S2' will be initialized after base 'T1::S3'}}
|
|
|
|
S3() { };
|
2010-03-29 13:13:12 +08:00
|
|
|
};
|
|
|
|
}
|
2010-04-10 15:37:23 +08:00
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
struct Foo { Foo(); };
|
|
|
|
class A {
|
|
|
|
template <class T> A(T *t) :
|
|
|
|
y(), // expected-warning {{field 'y' will be initialized after field 'x'}}
|
|
|
|
x()
|
|
|
|
{}
|
|
|
|
Foo x;
|
|
|
|
Foo y;
|
|
|
|
};
|
|
|
|
}
|
2010-04-10 17:28:51 +08:00
|
|
|
|
|
|
|
// PR6575: this should not crash
|
|
|
|
namespace test3 {
|
|
|
|
struct MyClass {
|
|
|
|
MyClass() : m_int(0) {}
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int m_int;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2010-05-21 07:49:34 +08:00
|
|
|
|
|
|
|
namespace PR7179 {
|
|
|
|
struct X
|
|
|
|
{
|
|
|
|
struct Y
|
|
|
|
{
|
|
|
|
template <class T> Y(T x) : X(x) { }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2013-01-17 16:49:22 +08:00
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
struct foo {
|
|
|
|
struct {
|
|
|
|
int a;
|
|
|
|
int b;
|
|
|
|
};
|
|
|
|
foo() : b(), a() { // expected-warning {{field 'b' will be initialized after field 'a'}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|