Author: ahatanak Date: Tue Jun 12 22:26:23 2018 New Revision: 334569 URL: http://llvm.org/viewvc/llvm-project?rev=334569&view=rev Log: [Sema] When the address of a member function is used as a template argument, use the context in which it is used for checking its accessibility.
This fixes PR32898. rdar://problem/33737747 Differential Revision: https://reviews.llvm.org/D36918 Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp cfe/trunk/test/SemaCXX/access.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=334569&r1=334568&r2=334569&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jun 12 22:26:23 2018 @@ -3803,10 +3803,16 @@ Sema::TemplateDeductionResult Sema::Dedu return Result; } + // Capture the context in which the function call is made. This is the context + // that is needed when the accessibility of template arguments is checked. + DeclContext *CallingCtx = CurContext; + return FinishTemplateArgumentDeduction( FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info, - &OriginalCallArgs, PartialOverloading, - [&]() { return CheckNonDependent(ParamTypesForArgChecking); }); + &OriginalCallArgs, PartialOverloading, [&, CallingCtx]() { + ContextRAII SavedContext(*this, CallingCtx); + return CheckNonDependent(ParamTypesForArgChecking); + }); } QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType, Modified: cfe/trunk/test/SemaCXX/access.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access.cpp?rev=334569&r1=334568&r2=334569&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/access.cpp (original) +++ cfe/trunk/test/SemaCXX/access.cpp Tue Jun 12 22:26:23 2018 @@ -169,3 +169,50 @@ 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 template 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'}} + } + + // r325321 caused an assertion failure when the following code was compiled. + class A { + template <typename Type> static bool foo1() { return true; } + + public: + void init(bool c) { + if (c) { + auto f = foo1<int>; + } + } + }; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits