This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/8271: Templates and pointers to const member functions
- From: René Møller Fonseca <fonseca at mip dot sdu dot dk>
- To: gcc-gnats at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org,bangerth at ticam dot utexas dot edu, gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: Tue, 07 Jan 2003 20:18:51 +0100
- Subject: Re: c++/8271: Templates and pointers to const member functions
- Organization: The Maersk Institute, University of Southern Denmark
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8271
Hi,
It is GCC that is wrong. The qualifiers are part of the type and must not be ignored. Here is a more elaborate implementation.
#include <iostream>
using namespace std;
class MyClass {
public:
void mutableMethod() throw() {
cout << __func__ << endl;
}
void constMethod() const throw() {
cout << __func__ << endl;
}
void volatileMethod() volatile throw() {
cout << __func__ << endl;
}
void constVolatileMethod() const volatile throw() {
cout << __func__ << endl;
}
};
MyClass* o = new MyClass();
template<class CLASS>
void mFunction(void (CLASS::* method)()) {
(o->*method)();
}
template<class CLASS>
void cFunction(void (CLASS::* method)() const) {
(o->*method)();
}
template<class CLASS>
void vFunction(void (CLASS::* method)() volatile) {
(o->*method)();
}
template<class CLASS>
void cvFunction(void (CLASS::* method)() const volatile) {
(o->*method)();
}
int main() {
// cFunction(&MyClass::mutablemethod); // ERROR
cFunction(&MyClass::constMethod); // OK
mFunction(&MyClass::mutableMethod); // OK
mFunction(&MyClass::constMethod); // ERROR - GCC bug
// vFunction(&MyClass::volatileMethod); // ERROR
vFunction(&MyClass::volatileMethod); // OK
mFunction(&MyClass::constVolatileMethod); // ERROR - GCC bug
cFunction(&MyClass::constVolatileMethod); // ERROR - GCC bug
vFunction(&MyClass::constVolatileMethod); // ERROR - GCC bug
cvFunction(&MyClass::constVolatileMethod); // OK
return 0;
}
<<<<
The generated output (using GCC-3.2):
constMethod
mutableMethod
constMethod
volatileMethod
constVolatileMethod
constVolatileMethod
constVolatileMethod
constVolatileMethod
cheers,
René