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 | |