ahatanak created this revision.

Sema::CheckAddressOfMemberAccess was disregarding the context in which the 
member pointer was referenced.

This patch fixes PR32898.

rdar://problem/33737747


https://reviews.llvm.org/D36918

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


Index: test/SemaCXX/access.cpp
===================================================================
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,29 @@
   }
   void bar() { foo<void>(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template<class T, void(T::*pMethod)()>
+  void func0() {}
+
+  template<class T>
+  void func1(void(*fn)()) {} // expected-note {{candidate function not viable: 
no overload of 'func0' matching 'void (*)()' for 1st argument}}
+
+  class C {
+    friend void friendFunc();
+    void overloadedMethod();
+  public:
+    void overloadedMethod(int);
+    void method() {
+      func1<int>(&func0<C, &C::overloadedMethod>);
+    }
+  };
+
+  void friendFunc() {
+    func1<int>(&func0<C, &C::overloadedMethod>);
+  }
+
+  void nonFriendFunc() {
+    func1<int>(&func0<C, &C::overloadedMethod>); // expected-error {{no 
matching function for call to 'func1'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===================================================================
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
                       /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+    return AR_accessible;
+
   Entity.setDiag(diag::err_access)
     << Ovl->getSourceRange();
 


Index: test/SemaCXX/access.cpp
===================================================================
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,29 @@
   }
   void bar() { foo<void>(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template<class T, void(T::*pMethod)()>
+  void func0() {}
+
+  template<class T>
+  void func1(void(*fn)()) {} // expected-note {{candidate function not viable: no overload of 'func0' matching 'void (*)()' for 1st argument}}
+
+  class C {
+    friend void friendFunc();
+    void overloadedMethod();
+  public:
+    void overloadedMethod(int);
+    void method() {
+      func1<int>(&func0<C, &C::overloadedMethod>);
+    }
+  };
+
+  void friendFunc() {
+    func1<int>(&func0<C, &C::overloadedMethod>);
+  }
+
+  void nonFriendFunc() {
+    func1<int>(&func0<C, &C::overloadedMethod>); // expected-error {{no matching function for call to 'func1'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===================================================================
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
                       /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+    return AR_accessible;
+
   Entity.setDiag(diag::err_access)
     << Ovl->getSourceRange();
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D36918: [Sema] Take... Akira Hatanaka via Phabricator via cfe-commits

Reply via email to