access to the (elevated) access of the accessed declaration, if applicable, rather than plunking that access onto the end after we've calculated the inheritance access. Also, being a friend of a derived class gives you public access to its members (subject to later modification by further inheritance); it does not simply ignore a single location of restricted inheritance. Also, when computing the best unprivileged path to a subobject, preserve the information that the worst path might be AS_none (forbidden) rather than a minimum of AS_private. llvm-svn: 98899
92 lines
1.4 KiB
C++
92 lines
1.4 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -faccess-control -verify %s
|
|
namespace T1 {
|
|
|
|
class A { };
|
|
class B : private A { }; // expected-note {{declared private here}}
|
|
|
|
void f(B* b) {
|
|
A *a = b; // expected-error{{cannot cast 'T1::B' to its private base class 'T1::A'}}
|
|
}
|
|
|
|
}
|
|
|
|
namespace T2 {
|
|
|
|
class A { };
|
|
class B : A { }; // expected-note {{implicitly declared private here}}
|
|
|
|
void f(B* b) {
|
|
A *a = b; // expected-error {{cannot cast 'T2::B' to its private base class 'T2::A'}}
|
|
}
|
|
|
|
}
|
|
|
|
namespace T3 {
|
|
|
|
class A { };
|
|
class B : public A { };
|
|
|
|
void f(B* b) {
|
|
A *a = b;
|
|
}
|
|
|
|
}
|
|
|
|
namespace T4 {
|
|
|
|
class A {};
|
|
|
|
class B : private virtual A {};
|
|
class C : public virtual A {};
|
|
|
|
class D : public B, public C {};
|
|
|
|
void f(D *d) {
|
|
// This takes the D->C->B->A path.
|
|
A *a = d;
|
|
}
|
|
|
|
}
|
|
|
|
namespace T5 {
|
|
class A {};
|
|
|
|
class B : private A {
|
|
void f(B *b) {
|
|
A *a = b;
|
|
}
|
|
};
|
|
}
|
|
|
|
namespace T6 {
|
|
class C;
|
|
|
|
class A {};
|
|
|
|
class B : private A { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}}
|
|
void f(C* c);
|
|
};
|
|
|
|
class C : public B {
|
|
void f(C *c) {
|
|
A* a = c; // expected-error {{cannot cast 'T6::C' to its private base class 'T6::A'}} \
|
|
// expected-error {{'A' is a private member of 'T6::A'}}
|
|
}
|
|
};
|
|
|
|
void B::f(C *c) {
|
|
A *a = c;
|
|
}
|
|
}
|
|
|
|
namespace T7 {
|
|
class A {};
|
|
class B : public A {};
|
|
class C : private B {
|
|
void f(C *c) {
|
|
A* a = c; // okay
|
|
}
|
|
};
|
|
}
|
|
|