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]

const and conversion sequence


Having recently upgraded to your new compiler (990927 snapshot. All my
template code is very happy now :), I've discovered a new warning that
wasn't issued before:

I have a memory block class like this:

class A {
public:
    operator void* (void) { return (m_Data); }
    operator const void* (void) const { return (m_Data); }
private:
    void* m_Data;
};

And I'm using it as a pointer substitute:

A a;
void* p;
if (0 == memcmp (a, p, 10))
    printf ("Equal");

Then the following message is given by the compiler:

warning: choosing `A::operator void * ()' over `A::operator const void * () const'
warning:   for conversion from `A' to `const void *'
warning:   because conversion sequence for the argument is better

It's a bit unclear to me why using the void* is better, since
memcmp takes a const void* and a const void* operator is available.
Previous versions of egcs (I've upgraded from a development version
released sometime last fall) always chose the const operator by
default, which was exactly what I wanted.

If the current behaviour is correct, then is there another way to
define the conversion rules for A, so that it can be used in both
const and non-const contexts?
-- 

						Mike

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| msharov@sprynet.com | US/WA/Seattle | GCSL+++ | 8)|
 \\\\\\\\\\\\\\\\\\|||||||///////////////////////////


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