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