2009-07-10 03:59:47 +08:00
|
|
|
// RUN: clang-cc -Wreorder -fsyntax-only -verify %s
|
2008-11-05 12:29:56 +08:00
|
|
|
class A {
|
|
|
|
int m;
|
2009-07-01 07:26:25 +08:00
|
|
|
A() : A::m(17) { } // expected-error {{member initializer 'm' does not name a non-static data member or base class}}
|
2009-07-23 08:42:24 +08:00
|
|
|
A(int);
|
2008-11-05 12:29:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class B : public A {
|
|
|
|
public:
|
|
|
|
B() : A(), m(1), n(3.14) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m;
|
|
|
|
float n;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class C : public virtual B {
|
|
|
|
public:
|
|
|
|
C() : B() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
class D : public C {
|
|
|
|
public:
|
|
|
|
D() : B(), C() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
class E : public D, public B {
|
|
|
|
public:
|
2009-07-30 05:26:28 +08:00
|
|
|
E() : B(), D() { } // expected-error{{base class initializer 'class B' names both a direct base class and an inherited virtual base class}}
|
2008-11-05 12:29:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef int INT;
|
|
|
|
|
|
|
|
class F : public B {
|
|
|
|
public:
|
|
|
|
int B;
|
|
|
|
|
|
|
|
F() : B(17),
|
|
|
|
m(17), // expected-error{{member initializer 'm' does not name a non-static data member or base class}}
|
2009-02-20 07:45:49 +08:00
|
|
|
INT(17) // expected-error{{constructor initializer 'INT' (aka 'int') does not name a class}}
|
2008-11-05 12:29:56 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2008-11-11 00:59:40 +08:00
|
|
|
|
|
|
|
class G : A {
|
|
|
|
G() : A(10); // expected-error{{expected '{'}}
|
|
|
|
};
|
2009-03-25 10:58:17 +08:00
|
|
|
|
|
|
|
void f() : a(242) { } // expected-error{{only constructors take base initializers}}
|
|
|
|
|
|
|
|
class H : A {
|
|
|
|
H();
|
|
|
|
};
|
|
|
|
|
|
|
|
H::H() : A(10) { }
|
|
|
|
|
2009-07-01 01:34:52 +08:00
|
|
|
|
|
|
|
class X {};
|
|
|
|
class Y {};
|
|
|
|
|
|
|
|
struct S : Y, virtual X {
|
|
|
|
S ();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Z : S {
|
2009-07-10 03:59:47 +08:00
|
|
|
Z() : X(), S(), E() {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}}
|
2009-07-01 01:34:52 +08:00
|
|
|
};
|
|
|
|
|
2009-07-01 05:52:59 +08:00
|
|
|
class U {
|
|
|
|
union { int a; char* p; };
|
|
|
|
union { int b; double d; };
|
|
|
|
|
|
|
|
U() : a(1), p(0), d(1.0) {} // expected-error {{multiple initializations given for non-static member 'p'}} \
|
|
|
|
// expected-note {{previous initialization is here}}
|
|
|
|
};
|
|
|
|
|
2009-07-01 07:26:25 +08:00
|
|
|
struct V {};
|
|
|
|
struct Base {};
|
|
|
|
struct Base1 {};
|
|
|
|
|
|
|
|
struct Derived : Base, Base1, virtual V {
|
|
|
|
Derived ();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Current : Derived {
|
|
|
|
int Derived;
|
2009-07-10 03:59:47 +08:00
|
|
|
Current() : Derived(1), ::Derived(), // expected-warning {{member 'Derived' will be initialized after}} \
|
|
|
|
// expected-note {{base '::Derived'}} \
|
|
|
|
// expected-warning {{base class '::Derived' will be initialized after}}
|
2009-07-01 07:26:25 +08:00
|
|
|
::Derived::Base(), // expected-error {{type '::Derived::Base' is not a direct or virtual base of 'Current'}}
|
|
|
|
Derived::Base1(), // expected-error {{type 'Derived::Base1' is not a direct or virtual base of 'Current'}}
|
2009-07-10 03:59:47 +08:00
|
|
|
Derived::V(), // expected-note {{base 'Derived::V'}}
|
2009-07-01 07:26:25 +08:00
|
|
|
::NonExisting(), // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
|
|
|
|
INT::NonExisting() {} // expected-error {{expected a class or namespace}} \
|
2009-09-09 23:08:12 +08:00
|
|
|
// expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
|
2009-07-01 07:26:25 +08:00
|
|
|
};
|
2009-07-24 07:32:59 +08:00
|
|
|
|
|
|
|
// FIXME. This is bad message!
|
2009-09-09 23:08:12 +08:00
|
|
|
struct M { // expected-note {{candidate function}} \
|
|
|
|
// expected-note {{candidate function}}
|
|
|
|
M(int i, int j); // expected-note {{candidate function}} \
|
|
|
|
// // expected-note {{candidate function}}
|
2009-07-24 07:32:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct N : M {
|
2009-09-09 23:08:12 +08:00
|
|
|
N() : M(1), // expected-error {{no matching constructor for initialization of 'M'}}
|
2009-07-24 07:32:59 +08:00
|
|
|
m1(100) { } // expected-error {{no matching constructor for initialization of 'm1'}}
|
|
|
|
M m1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct P : M { // expected-error {{default constructor for 'struct M' is missing in initialization of base class}}
|
|
|
|
P() { }
|
2009-07-28 03:53:49 +08:00
|
|
|
M m; // expected-error {{default constructor for 'struct M' is missing in initialization of member}}
|
2009-07-24 07:32:59 +08:00
|
|
|
};
|
|
|
|
|
2009-07-25 04:28:49 +08:00
|
|
|
struct Q {
|
2009-09-09 23:08:12 +08:00
|
|
|
Q() : f1(1,2), // expected-error {{Too many arguments for member initializer 'f1'}}
|
2009-07-25 04:28:49 +08:00
|
|
|
pf(0.0) { } // expected-error {{incompatible type passing 'double', expected 'float *'}}
|
|
|
|
float f1;
|
|
|
|
|
|
|
|
float *pf;
|
|
|
|
};
|