summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-03-27 19:01:12 +0000
committerAnders Carlsson <andersca@mac.com>2009-03-27 19:01:12 +0000
commitaf06b977f9aaae7440032d6754729365d11f00ec (patch)
treeb0133aa480410ad0ac84ff406a26d5004dca2446
parent93d35acb287038a9585e16aa72711e24112a4dc3 (diff)
downloadbcm5719-llvm-af06b977f9aaae7440032d6754729365d11f00ec.tar.gz
bcm5719-llvm-af06b977f9aaae7440032d6754729365d11f00ec.zip
It is OK to cast to a private base class if the current member belongs to the class that the private base class is a base of:
class A {}; class B : private A { void f(B *b) { A* a = b; } }; llvm-svn: 67860
-rw-r--r--clang/lib/Sema/SemaAccess.cpp9
-rw-r--r--clang/test/SemaCXX/access-base-class.cpp31
2 files changed, 38 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 85e1c2ed883..cc212434b79 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -55,6 +55,10 @@ bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base,
const CXXBaseSpecifier *InacessibleBase = 0;
+ const CXXRecordDecl* CurrentClassDecl = 0;
+ if (CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(getCurFunctionDecl()))
+ CurrentClassDecl = MD->getParent();
+
for (BasePaths::paths_iterator Path = Paths.begin(), PathsEnd = Paths.end();
Path != PathsEnd; ++Path) {
@@ -71,8 +75,9 @@ bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base,
// Nothing to do.
break;
case AS_private:
- // FIXME: Check if the current function is a member or friend.
- FoundInaccessibleBase = true;
+ // FIXME: Check if the current function/class is a friend.
+ if (CurrentClassDecl != Element->Class)
+ FoundInaccessibleBase = true;
break;
case AS_protected:
// FIXME: Implement
diff --git a/clang/test/SemaCXX/access-base-class.cpp b/clang/test/SemaCXX/access-base-class.cpp
index 29586759b04..f98437695ef 100644
--- a/clang/test/SemaCXX/access-base-class.cpp
+++ b/clang/test/SemaCXX/access-base-class.cpp
@@ -49,3 +49,34 @@ void f(D *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 {{'private' inheritance specifier here}}
+ void f(C* c);
+ };
+
+ class C : public B {
+ void f(C *c) {
+ A* a = c; // expected-error {{conversion from 'class T6::C' to inaccessible base class 'class T6::A'}} \
+ expected-error {{incompatible type initializing 'class T6::C *', expected 'class T6::A *'}}
+ }
+ };
+
+ void B::f(C *c) {
+ A *a = c;
+ }
+}
OpenPOWER on IntegriCloud