This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: const and conversion sequence
- To: msharov at sprynet dot com
- Subject: Re: const and conversion sequence
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sat, 9 Oct 1999 10:48:50 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- References: <199910050439.VAA01038@localhost>
> 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