This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/48078] New: gcc accepts-invalid: taking address of private member function from template function
- From: "cgd at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 11 Mar 2011 17:26:54 +0000
- Subject: [Bug c++/48078] New: gcc accepts-invalid: taking address of private member function from template function
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: cgd@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.