1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 namespace T1 { 3 4 class A { }; 5 class B : private A { }; // expected-note {{declared private here}} 6 7 void f(B* b) { 8 A *a = b; // expected-error{{cannot cast 'T1::B' to its private base class 'T1::A'}} 9 } 10 11 } 12 13 namespace T2 { 14 15 class A { }; 16 class B : A { }; // expected-note {{implicitly declared private here}} 17 18 void f(B* b) { 19 A *a = b; // expected-error {{cannot cast 'T2::B' to its private base class 'T2::A'}} 20 } 21 22 } 23 24 namespace T3 { 25 26 class A { }; 27 class B : public A { }; 28 29 void f(B* b) { 30 A *a = b; 31 } 32 33 } 34 35 namespace T4 { 36 37 class A {}; 38 39 class B : private virtual A {}; 40 class C : public virtual A {}; 41 42 class D : public B, public C {}; 43 44 void f(D *d) { 45 // This takes the D->C->B->A path. 46 A *a = d; 47 } 48 49 } 50 51 namespace T5 { 52 class A {}; 53 54 class B : private A { 55 void f(B *b) { 56 A *a = b; 57 } 58 }; 59 } 60 61 namespace T6 { 62 class C; 63 64 class A {}; // expected-note{{member is declared here}} 65 66 class B : private A { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} 67 void f(C* c); 68 }; 69 70 class C : public B { 71 void f(C *c) { 72 A* a = c; // expected-error {{cannot cast 'T6::C' to its private base class 'T6::A'}} \ 73 // expected-error {{'A' is a private member of 'T6::A'}} 74 } 75 }; 76 77 void B::f(C *c) { 78 A *a = c; 79 } 80 } 81 82 namespace T7 { 83 class A {}; 84 class B : public A {}; 85 class C : private B { 86 void f(C *c) { 87 A* a = c; // okay 88 } 89 }; 90 } 91 92