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]

Re: const and conversion sequence


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

Regards,
Martin

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