[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 18 22:28:03 PDT 2017
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36918.111799.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170819/e510e79b/attachment.bin>
More information about the cfe-commits
mailing list