C++ PATCH for -Wwrite-strings
Gabriel Dos Reis
gdr@integrable-solutions.net
Mon Feb 13 01:55:00 GMT 2006
This patchlet consolidates the earlier patch that removed
-fconst-strings. Now warn_write_strings is taken care of by the "opt"
machinery. I've added testcases to verify the default and alterations
by command line options.
Bootstrapped and regtested on an i686-pc-linux-gnu.
Applied to mainline.
-- Gaby
2006-02-12 Gabriel Dos Reis <gdr@integrable-solutions.net>
* doc/invoke.texi (-Write-strings): Document that it is enabled by
default.
* c.opt (-Wwrite-strings): Declare variable warn_write_strings.
Clarify documentation.
* c-common.h (warn_write_strings): Remove.
* c-common.c (warn_write_strings): Likewise.
* c-opts.c (c_common_init_options): Enable -Wwrite-strings by
default for C++.
testsuite/
2006-02-12 Gabriel Dos Reis <gdr@integrable-solutions.net>
* g++.dg/warn/no-write-strings.C: New test.
* g++.dg/warn/write-strings.C: Likewise.
* g++.dg/warn/write-strings-default.C: Likewise.
*** c-common.c (revision 110900)
--- c-common.c (local)
*************** int flag_no_asm;
*** 265,275 ****
int flag_signed_bitfields = 1;
- /* Nonzero means warn about deprecated conversion from string constant to
- `char *'. */
-
- int warn_write_strings;
-
/* Warn about #pragma directives that are not recognized. */
int warn_unknown_pragmas; /* Tri state variable. */
--- 265,270 ----
*** c-common.h (revision 110900)
--- c-common.h (local)
*************** extern int flag_const_strings;
*** 406,416 ****
extern int flag_signed_bitfields;
- /* Nonzero means warn about deprecated conversion from string constant to
- `char *'. */
-
- extern int warn_write_strings;
-
/* Warn about #pragma directives that are not recognized. */
extern int warn_unknown_pragmas; /* Tri state variable. */
--- 406,411 ----
*** c-opts.c (revision 110900)
--- c-opts.c (local)
*************** c_common_init_options (unsigned int argc
*** 227,232 ****
--- 227,233 ----
flag_exceptions = c_dialect_cxx ();
warn_pointer_arith = c_dialect_cxx ();
+ warn_write_strings = c_dialect_cxx();
deferred_opts = XNEWVEC (struct deferred_opt, argc);
*** c.opt (revision 110900)
--- c.opt (local)
*************** C ObjC C++ ObjC++
*** 420,427 ****
Do not warn about using variadic macros when -pedantic
Wwrite-strings
! C ObjC C++ ObjC++
! Give strings the type \"array of char\"
Wpointer-sign
C ObjC Var(warn_pointer_sign) Init(-1)
--- 420,427 ----
Do not warn about using variadic macros when -pedantic
Wwrite-strings
! C ObjC C++ ObjC++ Var(warn_write_strings)
! In C++, nonzero means warn about deprecated conversion from string literals to `char *'. In C, similar warning, except that the conversion is of course not deprecated by the ISO C standard.
Wpointer-sign
C ObjC Var(warn_pointer_sign) Init(-1)
*** doc/invoke.texi (revision 110900)
--- doc/invoke.texi (local)
*************** When compiling C, give string constants
*** 3065,3071 ****
char[@var{length}]} so that
copying the address of one into a non-@code{const} @code{char *}
pointer will get a warning; when compiling C++, warn about the
! deprecated conversion from string constants to @code{char *}.
These warnings will help you find at
compile time code that can try to write into a string constant, but
only if you have been very careful about using @code{const} in
--- 3065,3072 ----
char[@var{length}]} so that
copying the address of one into a non-@code{const} @code{char *}
pointer will get a warning; when compiling C++, warn about the
! deprecated conversion from string literals to @code{char *}. This
! warning, by default, is enabled for C++ programs.
These warnings will help you find at
compile time code that can try to write into a string constant, but
only if you have been very careful about using @code{const} in
*** testsuite/g++.dg/warn/no-write-strings.C (revision 110900)
--- testsuite/g++.dg/warn/no-write-strings.C (local)
***************
*** 0 ****
--- 1,7 ----
+ // { dg-do compile }
+ // { dg-options -Wno-write-strings }
+
+ int main()
+ {
+ char* p = "Asgaard";
+ }
Property changes on: testsuite/g++.dg/warn/no-write-strings.C
___________________________________________________________________
Name: svn:mime-type
+text/cpp
*** testsuite/g++.dg/warn/write-strings-default.C (revision 110900)
--- testsuite/g++.dg/warn/write-strings-default.C (local)
***************
*** 0 ****
--- 1,7 ----
+ // { dg-do compile }
+ // Test the default for -Wwrite-strings
+
+ int main()
+ {
+ char* p = "Asgaard"; // { dg-warning "warning:.*deprecated.*" }
+ }
Property changes on: testsuite/g++.dg/warn/write-strings-default.C
___________________________________________________________________
Name: svn:mime-type
+text/cpp
*** testsuite/g++.dg/warn/write-strings.C (revision 110900)
--- testsuite/g++.dg/warn/write-strings.C (local)
***************
*** 0 ****
--- 1,7 ----
+ // { dg-do compile }
+ // { dg-options -Wwrite-strings }
+
+ int main()
+ {
+ char* p = "Asgaard"; // { dg-warning "warning:.*deprecated.*" }
+ }
Property changes on: testsuite/g++.dg/warn/write-strings.C
___________________________________________________________________
Name: svn:mime-type
+text/cpp
More information about the Gcc-patches
mailing list