This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/8271: Templates and pointers to const member functions


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é


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]