This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
const and conversion sequence
- To: gcc-bugs at gcc dot gnu dot org
- Subject: const and conversion sequence
- From: msharov at sprynet dot com
- Date: Mon, 4 Oct 1999 21:39:39 -0700 (PDT)
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)|
\\\\\\\\\\\\\\\\\\|||||||///////////////////////////