Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -6927,7 +6927,8 @@ sema::TemplateDeductionInfo &Info, SmallVectorImpl const *OriginalCallArgs = nullptr, bool PartialOverloading = false, - llvm::function_ref CheckNonDependent = []{ return false; }); + llvm::function_ref CheckNonDependent = + [](DeclContext *){ return false; }); TemplateDeductionResult DeduceTemplateArguments( FunctionTemplateDecl *FunctionTemplate, Index: lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -3170,7 +3170,8 @@ unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, TemplateDeductionInfo &Info, SmallVectorImpl const *OriginalCallArgs, - bool PartialOverloading, llvm::function_ref CheckNonDependent) { + bool PartialOverloading, + llvm::function_ref CheckNonDependent) { // Unevaluated SFINAE context. EnterExpressionEvaluationContext Unevaluated( *this, Sema::ExpressionEvaluationContext::Unevaluated); @@ -3185,6 +3186,7 @@ if (Inst.isInvalid()) return TDK_InstantiationDepth; + DeclContext *CallingCtx = CurContext; ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl()); // C++ [temp.deduct.type]p2: @@ -3206,7 +3208,7 @@ // P with a type that was non-dependent before substitution of any // explicitly-specified template arguments, if the corresponding argument // A cannot be implicitly converted to P, deduction fails. - if (CheckNonDependent()) + if (CheckNonDependent(CallingCtx)) return TDK_NonDependentConversionFailure; // Form the template argument list from the deduced template arguments. @@ -3799,8 +3801,10 @@ return FinishTemplateArgumentDeduction( FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info, - &OriginalCallArgs, PartialOverloading, - [&]() { return CheckNonDependent(ParamTypesForArgChecking); }); + &OriginalCallArgs, PartialOverloading, [&](DeclContext *CallingCtx) { + ContextRAII SavedContext(*this, CallingCtx); + return CheckNonDependent(ParamTypesForArgChecking); + }); } QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType, Index: test/SemaCXX/access.cpp =================================================================== --- test/SemaCXX/access.cpp +++ test/SemaCXX/access.cpp @@ -169,3 +169,38 @@ } 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'}} + } +}