This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to change warn_write_strings to flag_const_strings
- To: jason at cygnus dot com (Jason Merrill)
- Subject: Re: Patch to change warn_write_strings to flag_const_strings
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Sat, 15 Aug 1998 20:28:51 +0200 (CEST)
- Cc: egcs-patches at cygnus dot com
| For C++, string constants are `const char[]' by default, so I'd like to
| change the flag that controls this behavior in c-common.c, and in any case
| it seems odd to control semantics with a warn_* flag. What do you think?
Unfortunately, I don't understand the patch :/.
Does this change the behaviour for C++ such that string constants
are ALWAYS const? Independent of any -W... flag?
Ie,
void foo(char *s);
void foo(const char *s);
...
foo("Hello world");
calls _always_ the second foo() ?
I wish it would :)
Thanks,
--
Carlo Wood <carlo@runaway.xs4all.nl>
PS Maybe I need more sleep, but isn't the following incorrect?
(behaviour of egcs-2.91.53):
~/tmp>g++ -W -Wall -Wwrite-strings str.cc
str.cc: In function `int main()':
str.cc:15: warning: initialization to `char *' from `const char *' discards const
str.cc:15: warning: unused variable `char * x'
~/tmp>a.out
foo(char *); "Hello world" <-- should call foo(const char *);
foo(const char *); "jaja"
foo(const char *); "12345"
----------------str.cc:
#include <iostream>
void foo(char *s)
{
cout << "foo(char *);" << " \"" << s << '"' << endl;
}
void foo(const char *s)
{
cout << "foo(const char *);" << " \"" << s << '"' << endl;
}
main()
{
char *x = "This must cause a warning"; // <-- str.cc:15
foo("Hello world");
const char *p = "jaja";
foo(p);
const char q[14] = { '1', '2', '3', '4', '5', 0 };
foo(q);
}
---------------------------------------------------------------