string is const char [] ?

Carlo Wood carlo@runaway.xs4all.nl
Thu Jun 25 18:53:00 GMT 1998


| Here is a real bug in egcs:
| 
| void f(      char *) {}
| voif f(const char *) {}
| 
| f("test not const"); // error in egcs. f(const char *) must be called,
|                      // because the type of string literals now is
|                      // array of n const char. However egcs calls
|                      // f(char*). -Wwrite-strings has no effect.
|                      // And even warning is surpressed.
| 
| Oleg.

Shouldn't this be added as a test in the testsuite?

Carlo

----

PS

~>/usr/src/egcs/egcs-cvs-objdir/gcc/g++ -B/usr/src/egcs/egcs-cvs-objdir/gcc/ -I/usr/src/egcs/egcs-cvs/libstdc++ -I/usr/src/egcs/egcs-cvs/libio -static -L/usr/src/egcs/egcs-cvs-objdir/libraries/libstdc++ -Wwrite-strings tst.cc
~>a.out
      char *
~>cat tst.cc
#include <iostream>

void f(      char *) { cout << "      char *" << endl; }
void f(const char *) { cout << "const char *" << endl; }
int main(void) { f("test not const"); }




More information about the Gcc mailing list