Skip to content

Commit

Permalink
[Sema] Take into account the current context when checking the
Browse files Browse the repository at this point in the history
accessibility of a class member.

This fixes PR32898.

rdar://problem/33737747

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

llvm-svn: 325321
  • Loading branch information
ahatanaka committed Feb 16, 2018
1 parent 7331a0b commit 82443d3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaAccess.cpp
Expand Up @@ -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();

Expand Down
35 changes: 35 additions & 0 deletions clang/test/SemaCXX/access.cpp
Expand Up @@ -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'}}
}
}

0 comments on commit 82443d3

Please sign in to comment.