Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2 | class A { |
| 3 | int m; |
Fariborz Jahanian | bcfad54 | 2009-06-30 23:26:25 +0000 | [diff] [blame^] | 4 | A() : A::m(17) { } // expected-error {{member initializer 'm' does not name a non-static data member or base class}} |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 5 | }; |
| 6 | |
| 7 | class B : public A { |
| 8 | public: |
| 9 | B() : A(), m(1), n(3.14) { } |
| 10 | |
| 11 | private: |
| 12 | int m; |
| 13 | float n; |
| 14 | }; |
| 15 | |
| 16 | |
| 17 | class C : public virtual B { |
| 18 | public: |
| 19 | C() : B() { } |
| 20 | }; |
| 21 | |
| 22 | class D : public C { |
| 23 | public: |
| 24 | D() : B(), C() { } |
| 25 | }; |
| 26 | |
| 27 | class E : public D, public B { |
| 28 | public: |
| 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 | |
| 33 | typedef int INT; |
| 34 | |
| 35 | class F : public B { |
| 36 | public: |
| 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 Lattner | d0344a4 | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 41 | INT(17) // expected-error{{constructor initializer 'INT' (aka 'int') does not name a class}} |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | }; |
Douglas Gregor | 3f08d18 | 2008-11-10 16:59:40 +0000 | [diff] [blame] | 45 | |
| 46 | class G : A { |
| 47 | G() : A(10); // expected-error{{expected '{'}} |
| 48 | }; |
Anders Carlsson | a7b3521 | 2009-03-25 02:58:17 +0000 | [diff] [blame] | 49 | |
| 50 | void f() : a(242) { } // expected-error{{only constructors take base initializers}} |
| 51 | |
| 52 | class H : A { |
| 53 | H(); |
| 54 | }; |
| 55 | |
| 56 | H::H() : A(10) { } |
| 57 | |
Fariborz Jahanian | 9da7201 | 2009-06-30 17:34:52 +0000 | [diff] [blame] | 58 | |
| 59 | class X {}; |
| 60 | class Y {}; |
| 61 | |
| 62 | struct S : Y, virtual X { |
| 63 | S (); |
| 64 | }; |
| 65 | |
| 66 | struct Z : S { |
| 67 | Z() : S(), X(), E() {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}} |
| 68 | }; |
| 69 | |
Fariborz Jahanian | 5ac3dfc | 2009-06-30 21:52:59 +0000 | [diff] [blame] | 70 | class 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 Jahanian | bcfad54 | 2009-06-30 23:26:25 +0000 | [diff] [blame^] | 78 | struct V {}; |
| 79 | struct Base {}; |
| 80 | struct Base1 {}; |
| 81 | |
| 82 | struct Derived : Base, Base1, virtual V { |
| 83 | Derived (); |
| 84 | }; |
| 85 | |
| 86 | struct 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 | }; |