[cfe-commits] r140244 - in /cfe/trunk: include/clang/Sema/Overload.h lib/Sema/SemaAccess.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp test/CXX/class.access/p6.cpp test/CodeGenCXX/delete.cpp

John McCall rjmccall at apple.com
Wed Sep 21 01:36:56 PDT 2011


Author: rjmccall
Date: Wed Sep 21 03:36:56 2011
New Revision: 140244

URL: http://llvm.org/viewvc/llvm-project?rev=140244&view=rev
Log:
Enforce access control for conversion operators used in contextual
conversions (rather than just call-arguments).


Modified:
    cfe/trunk/include/clang/Sema/Overload.h
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CXX/class.access/p6.cpp
    cfe/trunk/test/CodeGenCXX/delete.cpp

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Wed Sep 21 03:36:56 2011
@@ -256,7 +256,7 @@
     /// \brief The declaration that we found via name lookup, which might be
     /// the same as \c ConversionFunction or it might be a using declaration
     /// that refers to \c ConversionFunction.
-    NamedDecl *FoundConversionFunction;
+    DeclAccessPair FoundConversionFunction;
     
     void DebugPrint() const;
   };

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Wed Sep 21 03:36:56 2011
@@ -1551,8 +1551,7 @@
       Found.getAccess() == AS_public)
     return AR_accessible;
 
-  const RecordType *RT = ObjectExpr->getType()->getAs<RecordType>();
-  assert(RT && "found member operator but object expr not of record type");
+  const RecordType *RT = ObjectExpr->getType()->castAs<RecordType>();
   CXXRecordDecl *NamingClass = cast<CXXRecordDecl>(RT->getDecl());
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Sep 21 03:36:56 2011
@@ -2065,7 +2065,7 @@
                                        QualType Ty,
                                        CastKind Kind,
                                        CXXMethodDecl *Method,
-                                       NamedDecl *FoundDecl,
+                                       DeclAccessPair FoundDecl,
                                        Expr *From) {
   switch (Kind) {
   default: assert(0 && "Unhandled cast kind!");
@@ -2096,6 +2096,8 @@
     if (Result.isInvalid())
       return ExprError();
 
+    S.CheckMemberOperatorAccess(CastLoc, From, /*arg*/ 0, FoundDecl);
+
     return S.MaybeBindToTemporary(Result.get());
   }
   }

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Sep 21 03:36:56 2011
@@ -2509,7 +2509,7 @@
         User.EllipsisConversion = false;
       }
       User.ConversionFunction = Constructor;
-      User.FoundConversionFunction = Best->FoundDecl.getDecl();
+      User.FoundConversionFunction = Best->FoundDecl;
       User.After.setAsIdentityConversion();
       User.After.setFromType(ThisType->getAs<PointerType>()->getPointeeType());
       User.After.setAllToTypes(ToType);
@@ -2526,7 +2526,7 @@
       //   implicit object parameter of the conversion function.
       User.Before = Best->Conversions[0].Standard;
       User.ConversionFunction = Conversion;
-      User.FoundConversionFunction = Best->FoundDecl.getDecl();
+      User.FoundConversionFunction = Best->FoundDecl;
       User.EllipsisConversion = false;
 
       // C++ [over.ics.user]p2:
@@ -3367,7 +3367,7 @@
     ICS.UserDefined.Before = Best->Conversions[0].Standard;
     ICS.UserDefined.After = Best->FinalConversion;
     ICS.UserDefined.ConversionFunction = Best->Function;
-    ICS.UserDefined.FoundConversionFunction = Best->FoundDecl.getDecl();
+    ICS.UserDefined.FoundConversionFunction = Best->FoundDecl;
     ICS.UserDefined.EllipsisConversion = false;
     assert(ICS.UserDefined.After.ReferenceBinding &&
            ICS.UserDefined.After.DirectBinding &&
@@ -4754,8 +4754,7 @@
   Candidate.Conversions[0].UserDefined.Before = ObjectInit.Standard;
   Candidate.Conversions[0].UserDefined.EllipsisConversion = false;
   Candidate.Conversions[0].UserDefined.ConversionFunction = Conversion;
-  Candidate.Conversions[0].UserDefined.FoundConversionFunction
-    = FoundDecl.getDecl();
+  Candidate.Conversions[0].UserDefined.FoundConversionFunction = FoundDecl;
   Candidate.Conversions[0].UserDefined.After
     = Candidate.Conversions[0].UserDefined.Before;
   Candidate.Conversions[0].UserDefined.After.setAsIdentityConversion();

Modified: cfe/trunk/test/CXX/class.access/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p6.cpp?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/p6.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p6.cpp Wed Sep 21 03:36:56 2011
@@ -168,3 +168,25 @@
     void foo(int arg[__builtin_offsetof(B, ins)]);
   }
 }
+
+// rdar://problem/10155256
+namespace test8 {
+  class A {
+    typedef void* (A::*UnspecifiedBoolType)() const;
+    operator UnspecifiedBoolType() const; // expected-note {{implicitly declared private here}}
+  };
+
+  void test(A &a) {
+    if (a) return; // expected-error {{'operator void *(class test8::A::*)(void) const' is a private member of 'test8::A'}}
+  }
+}
+
+namespace test9 {
+  class A {
+    operator char*() const; // expected-note {{implicitly declared private here}}
+  };
+
+  void test(A &a) {
+    delete a; // expected-error {{'operator char *' is a private member of 'test9::A'}}
+  }
+}

Modified: cfe/trunk/test/CodeGenCXX/delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/delete.cpp?rev=140244&r1=140243&r2=140244&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/delete.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/delete.cpp Wed Sep 21 03:36:56 2011
@@ -30,7 +30,7 @@
 // PR5102
 template <typename T>
 class A {
-  operator T *() const;
+  public: operator T *() const;
 };
 
 void f() {





More information about the cfe-commits mailing list