This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C++ compiler bug ?
- To: Matthias Meixner <meixner at rbg dot informatik dot tu-darmstadt dot de>
- Subject: Re: C++ compiler bug ?
- From: Alexandre Oliva <oliva at lsd dot ic dot unicamp dot br>
- Date: 01 Mar 2000 15:11:08 -0300
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <38BCFC45.603A2114@rbg.informatik.tu-darmstadt.de>
On Mar 1, 2000, Matthias Meixner <meixner@rbg.informatik.tu-darmstadt.de> wrote:
> operator char *() { return s; }
> operator const char *() const { return s; }
> void foo(const char *s)
> string a("test");
> foo(a);
> t2.cxx:22: warning: choosing `string::operator char *()' over `string::operator const char *() const'
> t2.cxx:22: warning: for conversion from `string' to `const char *'
> t2.cxx:22: warning: because conversion sequence for the argument is better
> Conversion sequences:
> 1) string->const char *
> 2) string->char *->const char *
(1) is wrong. It should be:
1) string->string const->const char *
Add that to the warning message GCC prints, to clarify this common
misconception, and you'll see why gcc selects 2 over 1.
--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Enjoy Guaranį
Cygnus Solutions, a Red Hat company aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org} Write to mailing lists, not to me