http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48078
Summary: gcc accepts-invalid: taking address of private member function from template function Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: c...@google.com test case (created by Bill Clarke): class A { public: A() {} private: void APrivateMethod() { } }; // Enable this to get a (correct) compiler error. #if 0 void CallAPrivateMethod() { void (A::*fn)() = &A::APrivateMethod; A a; (a.*fn)(); } #endif template <typename T> void CallAPrivateMethodTemplate() { void (A::*fn)() = &A::APrivateMethod; A a; (a.*fn)(); } void CallAPrivateMethodViaTemplate() { CallAPrivateMethodTemplate<int>(); } compiles successfully (incorrectly AFAIU) with pre-4.6 (4.6.0 20110311) (I tested some versions of GCC back to 4.2.x, same problem. They had local mods, but none that should have caused a difference in this regard.) FYI, clang C++ front-end flags an error as expected: devtools/cpp_tests/x.cc:22:24: error: 'APrivateMethod' is a private member of 'A' void (A::*fn)() = &A::APrivateMethod; ^ devtools/cpp_tests/x.cc:8:7: note: declared private here void APrivateMethod() { } ^ 1 error generated.