[Bug c++/14830] compiler incorrectly diagnoses ambigous operator overload
iker at research dot att dot com
gcc-bugzilla@gcc.gnu.org
Mon Apr 5 04:12:00 GMT 2004
------- Additional Comments From iker at research dot att dot com 2004-04-05 04:11 -------
Subject: Re: compiler incorrectly diagnoses ambigous operator
overload
giovannibajo at libero dot it wrote:
> [over.ics.user] So, the converstion from float to char
> comes "for free" as the final standard conversion (in case
> somebody is wondering, standard conversions are those made
> on built-in types).
>
> I believe the code is in fact ill-formed.
>
Below is more of the relevant section.
It looks like the latter part of subsection [1] indicates
that the first standard conversion would convert the RHS to
the implicit this for the conversion functions of the class.
The second step would be to select the right conversion
function and in this case I think [4] would call for the
conversion to string as its an exact match (the last conversion
can be an Identity conversion, ie no conversion at all).
In addition, the short example in 13.3.3 seems to indicate that
the standard considers exact matches as "better".
Regards,
Iker Arizmendi
-----------------
13.3.3.1.2
1 A user defined conversion sequence consists of an initial standard
conversion sequence followed by a userdefined conversion (12.3) followed
by a second standard conversion sequence. If the userdefined conversion
is specified by a constructor (12.3.1), the initial standard conversion
sequence converts the source type to the type required by the argument
of the constructor. If the userdefined conversion is specified by a
conversion function (12.3.2), the initial standard conversion sequence
converts the source type to the implicit object parameter of the
conversion function.
2 The second standard conversion sequence converts
the result of the userdefined conversion to the target type for the
sequence. Since an implicit conversion sequence is an initialization,
the special rules for initialization by userdefined conversion apply
when selecting the best userdefined conversion for a userdefined
conversion sequence (see 13.3.3 and 13.3.3.1).
4 A conversion of an expression of class type to the same class type is
given Exact Match rank, and a conversion of an expression of class type
to a base class of that type is given Conversion rank, in spite of the
fact that a copy constructor (i.e., a userdefined conversion function)
is called for those cases.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14830
More information about the Gcc-bugs
mailing list