From: Akira Hatanaka Date: Fri, 16 Feb 2018 08:47:37 +0000 (+0000) Subject: [Sema] Take into account the current context when checking the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2867bd1baac03f84d4b6d48cb7d36aa64d209256;p=clang [Sema] Take into account the current context when checking the 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 --- diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 98a918bd7d..d2205dd239 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -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(); diff --git a/test/SemaCXX/access.cpp b/test/SemaCXX/access.cpp index 29a58a1388..0707ec25be 100644 --- a/test/SemaCXX/access.cpp +++ b/test/SemaCXX/access.cpp @@ -169,3 +169,38 @@ namespace ThisLambdaIsNotMyFriend { } void bar() { foo(); } } + +namespace OverloadedMemberFunctionPointer { + template + void func0() {} + + template + void func1() {} + + template + 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(&func0); + func2(&func1); + } + }; + + void friendFunc() { + func2(&func0); + func2(&func1); + } + + void nonFriendFunc() { + func2(&func0); // expected-error {{no matching function for call to 'func2'}} + func2(&func1); // expected-error {{no matching function for call to 'func2'}} + } +}