[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
Tue Jun 12 22:30:54 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334569: [Sema] When the address of a member function is used as a template (authored by ahatanak, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D36918?vs=148334&id=151102#toc
Repository:
rC Clang
https://reviews.llvm.org/D36918
Files:
lib/Sema/SemaTemplateDeduction.cpp
test/SemaCXX/access.cpp
Index: test/SemaCXX/access.cpp
===================================================================
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,50 @@
}
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>;
+ }
+ }
+ };
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===================================================================
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3803,10 +3803,16 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36918.151102.patch
Type: text/x-patch
Size: 2449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180613/7e22b7b3/attachment-0001.bin>
More information about the cfe-commits
mailing list