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: C++ compiler bug ?


> I have checked the final draft of the ANSI C++ standard (section 13.3.3.2)
> and I think, since opterator const char *() is an exact match, I think this 
> conversion operator should be used instead of operator char *().
> 
> Conversion sequences:
> 
> 1) string->const char *
> 2) string->char *->const char *
> 
> gcc selects 2 over 1.

Thanks for your bug report. Your analysis is incorrect, gcc selects
the right conversion sequence. The candidate sequences are


1) string -> string const & -> char const *
2) string -> string & -> char* -> char const *

because the implicit object argument must be converted to the
appropriate reference. According to 13.3.3/1, the standard conversion
sequences from the result of a user-defined conversion to the target
type are only considered if no conversion sequence for the arguments
is better, and. In conversion sequence 2), conversion for the
arguments is better, since it does not involve a qualification
conversion.

The gcc authors find that this is a confusing rule, hence the warning.

If you question this line of reasoning, please discuss it in one of
the public C++ fora first, eg. comp.lang.c++.moderated, or
comp.std.c++.

Regards,
Martin

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