[cfe-commits] r67860 - in /cfe/trunk: lib/Sema/SemaAccess.cpp test/SemaCXX/access-base-class.cpp

Anders Carlsson andersca at mac.com
Fri Mar 27 12:01:19 PDT 2009


Author: andersca
Date: Fri Mar 27 14:01:12 2009
New Revision: 67860

URL: http://llvm.org/viewvc/llvm-project?rev=67860&view=rev
Log:
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; }
};


Modified:
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/test/SemaCXX/access-base-class.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=67860&r1=67859&r2=67860&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Fri Mar 27 14:01:12 2009
@@ -55,6 +55,10 @@
   
   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 @@
         // 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

Modified: cfe/trunk/test/SemaCXX/access-base-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access-base-class.cpp?rev=67860&r1=67859&r2=67860&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/access-base-class.cpp (original)
+++ cfe/trunk/test/SemaCXX/access-base-class.cpp Fri Mar 27 14:01:12 2009
@@ -49,3 +49,34 @@
 }
 
 }
+
+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;
+  }
+}





More information about the cfe-commits mailing list