blob: a180d907f1b7669a1fd1315d9c8b20529ca6bfb7 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor7ad83902008-11-05 04:29:56 +00002class A {
3 int m;
Fariborz Jahanianbcfad542009-06-30 23:26:25 +00004 A() : A::m(17) { } // expected-error {{member initializer 'm' does not name a non-static data member or base class}}
Douglas Gregor7ad83902008-11-05 04:29:56 +00005};
6
7class B : public A {
8public:
9 B() : A(), m(1), n(3.14) { }
10
11private:
12 int m;
13 float n;
14};
15
16
17class C : public virtual B {
18public:
19 C() : B() { }
20};
21
22class D : public C {
23public:
24 D() : B(), C() { }
25};
26
27class E : public D, public B {
28public:
29 E() : B(), D() { } // expected-error{{base class initializer 'B' names both a direct base class and an inherited virtual base class}}
30};
31
32
33typedef int INT;
34
35class F : public B {
36public:
37 int B;
38
39 F() : B(17),
40 m(17), // expected-error{{member initializer 'm' does not name a non-static data member or base class}}
Chris Lattnerd0344a42009-02-19 23:45:49 +000041 INT(17) // expected-error{{constructor initializer 'INT' (aka 'int') does not name a class}}
Douglas Gregor7ad83902008-11-05 04:29:56 +000042 {
43 }
44};
Douglas Gregor3f08d182008-11-10 16:59:40 +000045
46class G : A {
47 G() : A(10); // expected-error{{expected '{'}}
48};
Anders Carlssona7b35212009-03-25 02:58:17 +000049
50void f() : a(242) { } // expected-error{{only constructors take base initializers}}
51
52class H : A {
53 H();
54};
55
56H::H() : A(10) { }
57
Fariborz Jahanian9da72012009-06-30 17:34:52 +000058
59class X {};
60class Y {};
61
62struct S : Y, virtual X {
63 S ();
64};
65
66struct Z : S {
67 Z() : S(), X(), E() {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}}
68};
69
Fariborz Jahanian5ac3dfc2009-06-30 21:52:59 +000070class U {
71 union { int a; char* p; };
72 union { int b; double d; };
73
74 U() : a(1), p(0), d(1.0) {} // expected-error {{multiple initializations given for non-static member 'p'}} \
75 // expected-note {{previous initialization is here}}
76};
77
Fariborz Jahanianbcfad542009-06-30 23:26:25 +000078struct V {};
79struct Base {};
80struct Base1 {};
81
82struct Derived : Base, Base1, virtual V {
83 Derived ();
84};
85
86struct Current : Derived {
87 int Derived;
88 Current() : Derived(1), ::Derived(),
89 ::Derived::Base(), // expected-error {{type '::Derived::Base' is not a direct or virtual base of 'Current'}}
90 Derived::Base1(), // expected-error {{type 'Derived::Base1' is not a direct or virtual base of 'Current'}}
91 Derived::V(),
92 ::NonExisting(), // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
93 INT::NonExisting() {} // expected-error {{expected a class or namespace}} \
94 // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
95};