]> granicus.if.org Git - clang/commitdiff
[Sema] Take into account the current context when checking the
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 16 Feb 2018 08:47:37 +0000 (08:47 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 16 Feb 2018 08:47:37 +0000 (08:47 +0000)
accessibility of a class member.

This fixes PR32898.

rdar://problem/33737747

Differential revision: https://reviews.llvm.org/D36918

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

lib/Sema/SemaAccess.cpp
test/SemaCXX/access.cpp

index 98a918bd7d638a937e254d98083a253638f94030..d2205dd239e89cafe9c6ee4677a4b8b325437927 100644 (file)
@@ -1793,6 +1793,11 @@ Sema::AccessResult Sema::CheckAddressOfMemberAccess(Expr *OvlExpr,
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
                       /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+      ::AR_accessible)
+    return AR_accessible;
+
   Entity.setDiag(diag::err_access)
     << Ovl->getSourceRange();
 
index 29a58a1388acf07ed8705188277545ec93ed162d..0707ec25be5caf6534784409db31e2251e0fd8de 100644 (file)
@@ -169,3 +169,38 @@ namespace ThisLambdaIsNotMyFriend {
   }
   void bar() { foo<void>(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template<class T, void(T::*pMethod)()>
+  void func0() {}
+
+  template<class T, void(T::*pMethod)(int)>
+  void func1() {}
+
+  template<class T>
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+    friend void friendFunc();
+    void overloadedMethod();
+  protected:
+    void overloadedMethod(int);
+  public:
+    void overloadedMethod(int, int);
+    void method() {
+      func2<int>(&func0<C, &C::overloadedMethod>);
+      func2<int>(&func1<C, &C::overloadedMethod>);
+    }
+  };
+
+  void friendFunc() {
+    func2<int>(&func0<C, &C::overloadedMethod>);
+    func2<int>(&func1<C, &C::overloadedMethod>);
+  }
+
+  void nonFriendFunc() {
+    func2<int>(&func0<C, &C::overloadedMethod>); // expected-error {{no matching function for call to 'func2'}}
+    func2<int>(&func1<C, &C::overloadedMethod>); // expected-error {{no matching function for call to 'func2'}}
+  }
+}