This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Syntax bug
- To: mmitchell at usa dot net
- Subject: Re: Syntax bug
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 10 Feb 1998 21:04:54 -0200
- Cc: "Pavel A. Kalugin" <kalugin at pc358 dot lps dot u-psud dot fr>, egcs-bugs at cygnus dot com
- References: <199801131714.SAA14494@pc358.lps.u-psud.fr><199802101142.LAA10904@quickstep.stanford.edu>
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