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: Syntax bug


[Mark, I hope you don't care I'm CC-ing to the list]

Mark Mitchell writes:

>>>>>> "Alexandre" == Alexandre Oliva <oliva@dcc.unicamp.br> writes:

Alexandre> But it should be able to tell because one is a const
Alexandre> member function and the other isn't (operator const
Alexandre> char *()const and operator char*()).  Since x is
Alexandre> non-const, the non-const version should be used.

> But, does it make a difference that one conversion operator
> returns `const char*' while the other returns `char*'?  I know that if
> both return types are the same the compiler should pick the non-const
> one, but is that true here too?

In fact, I was wrong.  I mistook operator char* as if it were
operator[] or such.  In the latter case, the constness of the member
function would make it possible for the compiler to select one of the
two member functions, but in this case, it isn't, because user
defined conversion sequences are involved.  We have:

X --operator char*()--> char*
X --CV qualification--> X const --operator const char*()const--> const char*

Although the second conversion seems worse than the first, user
defined conversion sequences are only comparable if they contain the
same user defined conversion function, which they don't, so the call
is really ambiguous.  Sorry for spreading misinformation, and thanks
for challenging it! :-)

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


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