reinterpret_cast failed to cast between const and non-const member function

The following code passes g++, but fails on Sun CC 5.8

class C {

public:

void fv();

void fc() const;

};

typedef void (C::*C_FUNC)();

typedef void (C::*C_CONST_FUNC)() const;

int main()

{

C_FUNC f1 = &C::fv;

C_CONST_FUNC f2 = &C::fc;

C_CONST_FUNC f3 = reinterpret_cast<C_CONST_FUNC>(&C::fv);

C_FUNC f4 = reinterpret_cast<C_FUNC>(&C::fc);

}

"recast.cc", line 15: Error: Cannot cast away const or volatile.

"recast.cc", line 16: Error: Cannot cast away const or volatile.

2 Error(s) detected.

Is this a bug of Sun CC?

Thanks.

huoq.

[683 byte] By [huoq] at [2007-11-26 11:04:00]
# 1
This is a bug in the Sun C++ compiler. A reinterpret_cast is not allowed to cast away constness, but the "const" on a non-static member func tion is not a "top-level" const, and is not being cast away.Please file a bug report at http://bugs.sun.com
clamage45 at 2007-7-7 3:17:57 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
I have filed a bug report for you: 6488558It will be visible at bugs.sun.com in a day or two.
clamage45 at 2007-7-7 3:17:57 > top of Java-index,Development Tools,Solaris and Linux Development Tools...