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; |
| 4 | }; |
| 5 | |
| 6 | class B : public A { |
| 7 | public: |
| 8 | B() : A(), m(1), n(3.14) { } |
| 9 | |
| 10 | private: |
| 11 | int m; |
| 12 | float n; |
| 13 | }; |
| 14 | |
| 15 | |
| 16 | class C : public virtual B { |
| 17 | public: |
| 18 | C() : B() { } |
| 19 | }; |
| 20 | |
| 21 | class D : public C { |
| 22 | public: |
| 23 | D() : B(), C() { } |
| 24 | }; |
| 25 | |
| 26 | class E : public D, public B { |
| 27 | public: |
| 28 | E() : B(), D() { } // expected-error{{base class initializer 'B' names both a direct base class and an inherited virtual base class}} |
| 29 | }; |
| 30 | |
| 31 | |
| 32 | typedef int INT; |
| 33 | |
| 34 | class F : public B { |
| 35 | public: |
| 36 | int B; |
| 37 | |
| 38 | F() : B(17), |
| 39 | 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] | 40 | 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] | 41 | { |
| 42 | } |
| 43 | }; |
Douglas Gregor | 3f08d18 | 2008-11-10 16:59:40 +0000 | [diff] [blame] | 44 | |
| 45 | class G : A { |
| 46 | G() : A(10); // expected-error{{expected '{'}} |
| 47 | }; |
Anders Carlsson | a7b3521 | 2009-03-25 02:58:17 +0000 | [diff] [blame] | 48 | |
| 49 | void f() : a(242) { } // expected-error{{only constructors take base initializers}} |
| 50 | |
| 51 | class H : A { |
| 52 | H(); |
| 53 | }; |
| 54 | |
| 55 | H::H() : A(10) { } |
| 56 | |
Fariborz Jahanian | 9da7201 | 2009-06-30 17:34:52 +0000 | [diff] [blame] | 57 | |
| 58 | class X {}; |
| 59 | class Y {}; |
| 60 | |
| 61 | struct S : Y, virtual X { |
| 62 | S (); |
| 63 | }; |
| 64 | |
| 65 | struct Z : S { |
| 66 | Z() : S(), X(), E() {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}} |
| 67 | }; |
| 68 | |
Fariborz Jahanian | 5ac3dfc | 2009-06-30 21:52:59 +0000 | [diff] [blame] | 69 | class U { |
| 70 | union { int a; char* p; }; |
| 71 | union { int b; double d; }; |
| 72 | |
| 73 | U() : a(1), p(0), d(1.0) {} // expected-error {{multiple initializations given for non-static member 'p'}} \ |
| 74 | // expected-note {{previous initialization is here}} |
| 75 | }; |
| 76 | |