Anders Carlsson | c4f1e87 | 2009-03-27 06:03:27 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | namespace T1 { |
| 3 | |
| 4 | class A { }; |
| 5 | class B : private A { }; // expected-note {{'private' inheritance specifier here}} |
| 6 | |
| 7 | void f(B* b) { |
| 8 | A *a = b; // expected-error{{conversion from 'class T1::B' to inaccessible base class 'class T1::A'}} \ |
| 9 | expected-error{{incompatible type initializing 'class T1::B *', expected 'class T1::A *'}} |
| 10 | } |
| 11 | |
| 12 | } |
| 13 | |
| 14 | namespace T2 { |
| 15 | |
| 16 | class A { }; |
| 17 | class B : A { }; // expected-note {{inheritance is implicitly 'private'}} |
| 18 | |
| 19 | void f(B* b) { |
| 20 | A *a = b; // expected-error {{conversion from 'class T2::B' to inaccessible base class 'class T2::A'}} \ |
| 21 | expected-error {{incompatible type initializing 'class T2::B *', expected 'class T2::A *'}} |
| 22 | } |
| 23 | |
| 24 | } |
| 25 | |
| 26 | namespace T3 { |
| 27 | |
| 28 | class A { }; |
| 29 | class B : public A { }; |
| 30 | |
| 31 | void f(B* b) { |
| 32 | A *a = b; |
| 33 | } |
| 34 | |
| 35 | } |
| 36 | |
| 37 | namespace T4 { |
| 38 | |
| 39 | class A {}; |
| 40 | |
| 41 | class B : private virtual A {}; |
| 42 | class C : public virtual A {}; |
| 43 | |
| 44 | class D : public B, public C {}; |
| 45 | |
| 46 | void f(D *d) { |
| 47 | // This takes the D->C->B->A path. |
| 48 | A *a = d; |
| 49 | } |
| 50 | |
| 51 | } |
Anders Carlsson | f8080a3 | 2009-03-27 19:01:12 +0000 | [diff] [blame] | 52 | |
| 53 | namespace T5 { |
| 54 | class A {}; |
| 55 | |
| 56 | class B : private A { |
| 57 | void f(B *b) { |
| 58 | A *a = b; |
| 59 | } |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | namespace T6 { |
| 64 | class C; |
| 65 | |
| 66 | class A {}; |
| 67 | |
| 68 | class B : private A { // expected-note {{'private' inheritance specifier here}} |
| 69 | void f(C* c); |
| 70 | }; |
| 71 | |
| 72 | class C : public B { |
| 73 | void f(C *c) { |
| 74 | A* a = c; // expected-error {{conversion from 'class T6::C' to inaccessible base class 'class T6::A'}} \ |
| 75 | expected-error {{incompatible type initializing 'class T6::C *', expected 'class T6::A *'}} |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | void B::f(C *c) { |
| 80 | A *a = c; |
| 81 | } |
| 82 | } |