This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++ compiler bug ?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: C++ compiler bug ?
- From: Matthias Meixner <meixner at rbg dot informatik dot tu-darmstadt dot de>
- Date: Wed, 01 Mar 2000 12:17:25 +0100
- Organization: TU Darmstadt, Rechnerbetriebsgruppe
Hello,
I think the following is a bug in the C++ compiler:
------------------------------------------------------
$> cat t2.cxx
class string {
char *s;
public:
string(const char *c) {s=c;}
operator char *() { return s; }
operator const char *() const { return s; }
};
void foo(const char *s)
{
}
main()
{
string a("test");
foo(a);
return 0;
}
$> gcc t2.cxx
t2.cxx: In method `string::string(const char *)':
t2.cxx:8: assignment to `char *' from `const char *' discards qualifiers
t2.cxx: In function `int main()':
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
$> gcc --version
2.95.2
--------------------------------------------------------------------
I have checked the final draft of the ANSI C++ standard (section 13.3.3.2)
and I think, since opterator const char *() is an exact match, I think this
conversion operator should be used instead of operator char *().
Conversion sequences:
1) string->const char *
2) string->char *->const char *
gcc selects 2 over 1.
Regards,
Matthias Meixner
--
Matthias Meixner meixner@rbg.informatik.tu-darmstadt.de
Technische Universität Darmstadt
Rechnerbetriebsgruppe Telefon (+49) 6151 16 6670
Wilhelminenstraße 7, D-64283 Darmstadt, Germany Fax (+49) 6151 16 4701