const and conversion sequence

Martin v. Loewis
Sun Oct 31 23:03:00 GMT 1999

> 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.

Thanks for your bug report. This behaviour is mandated by the C++
standard; a conversion operator is "better" if the conversion
sequences for the arguments are "better". The argument is of type
"A&", the parameter type is "A&" in one case (requiring only identity
conversion), and "A const &" in the other case (requiring
qualification conversion).

> 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 you where using egcs 2.91.x, then it already did what it does now -
it only did not warn about that.

> 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?

You can add a third operator

    operator const void* (void) { return (m_Data); }

Or you can just ignore the warning - it is harmless.


More information about the Gcc-bugs mailing list