]> granicus.if.org Git - clang/commitdiff
Access control for surrogate function calls. Required a moderately gross hack
authorJohn McCall <rjmccall@apple.com>
Thu, 28 Jan 2010 07:38:46 +0000 (07:38 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 28 Jan 2010 07:38:46 +0000 (07:38 +0000)
to get the access bits set properly in conversion sets.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94744 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/UnresolvedSet.h
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaOverload.cpp
test/CXX/class.access/p4.cpp

index d2e33edf08931f66e50f8ef76412192f1c76c3da..8bf7c11e6fc9246ca7d6a2dbb4442b91b28ffb8c 100644 (file)
@@ -147,6 +147,10 @@ public:
     decls().pop_back();
   }
 
+  void setAccess(iterator I, AccessSpecifier AS) {
+    I.ir->setInt(AS);
+  }
+
   void clear() { decls().clear(); }
   void set_size(unsigned N) { decls().set_size(N); }
 
index f65dc4bd668d861efa5ce0d5be09c2de17f66ea2..566e915bc0115fd8740acde7ad1c75ee6b30ec10 100644 (file)
@@ -2086,6 +2086,11 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
   if (Record->isInvalidDecl())
     return;
 
+  // Set access bits correctly on the directly-declared conversions.
+  UnresolvedSetImpl *Convs = Record->getConversionFunctions();
+  for (UnresolvedSetIterator I = Convs->begin(), E = Convs->end(); I != E; ++I)
+    Convs->setAccess(I, (*I)->getAccess());
+
   if (!Record->isAbstract()) {
     // Collect all the pure virtual methods and see if this is an abstract
     // class after all.
index 55259fca4f2ad8682c2bebbd5790a787faf344c1..86b1e37f10810483089b5f39bea01b0937d6d516 100644 (file)
@@ -6231,7 +6231,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
       = cast<CXXConversionDecl>(
                          Best->Conversions[0].UserDefined.ConversionFunction);
 
-    // FIXME: access control
+    CheckMemberOperatorAccess(LParenLoc, Object, Conv, Best->getAccess());
 
     // We selected one of the surrogate functions that converts the
     // object parameter to a function pointer. Perform the conversion
@@ -6246,8 +6246,8 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
                          CommaLocs, RParenLoc).release();
   }
 
-  if (getLangOptions().AccessControl)
-    CheckAccess(R, Best->Function, Best->getAccess());
+  CheckMemberOperatorAccess(LParenLoc, Object,
+                            Best->Function, Best->getAccess());
 
   // We found an overloaded operator(). Build a CXXOperatorCallExpr
   // that calls this method, using Object for the implicit object
index 0df17919a30d60f8eb96edcd8dae0ad90ae8cf18..97c632a07251e07d1b8d66af38d7b67db2ebd6e2 100644 (file)
@@ -39,15 +39,21 @@ namespace test1 {
     void operator+(Public&);
     void operator[](Public&);
     void operator()(Public&);
+    typedef void (*PublicSurrogate)(Public&);
+    operator PublicSurrogate() const;
   protected:
     void operator+(Protected&); // expected-note {{declared protected here}}
     void operator[](Protected&); // expected-note {{declared protected here}}
     void operator()(Protected&); // expected-note {{declared protected here}}
+    typedef void (*ProtectedSurrogate)(Protected&);
+    operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
   private:
     void operator+(Private&); // expected-note {{declared private here}}
     void operator[](Private&); // expected-note {{declared private here}}
     void operator()(Private&); // expected-note {{declared private here}}
     void operator-(); // expected-note {{declared private here}}
+    typedef void (*PrivateSurrogate)(Private&);
+    operator PrivateSurrogate() const; // expected-note {{declared private here}}
   };
   void operator+(const A &, Public&);
   void operator+(const A &, Protected&);
@@ -71,5 +77,9 @@ namespace test1 {
     ca + prot;
     ca + priv;
     -ca;
+    // These are all surrogate calls
+    ca(pub);
+    ca(prot); // expected-error {{access to protected member}}
+    ca(priv); // expected-error {{access to private member}}
   }
 }