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 ?


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


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