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 Mitchell writes:

>>>>>> "Pavel" == Pavel A Kalugin <kalugin@pc358.lps.u-psud.fr> writes:

Pavel> ////////////////////////////////////////////////////////////
Pavel> class X { public: X() : data(new char[10]){} ~X() {
Pavel> delete[] data; } operator const char* () const {return
Pavel> data;} operator char* () {return data;} private: char*
Pavel> data; };

Pavel> void foo() { X x; x[0]='q'; }
Pavel> ///////////////////////////////////////////////////////////////

Pavel> x.cpp: In function `void foo()': x.cpp:17: ambiguous
Pavel> conversion for array subscript

> That's a correct error message.  The compiler doesn't know whether to
> use the const char* conversion or the char* conversion.

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

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