This is the mail archive of the gcc-patches@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]

Patch to change warn_write_strings to flag_const_strings


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?

Fri Aug 14 14:12:59 1998  Jason Merrill  <jason@yorick.cygnus.com>

	* c-common.c (combine_strings): Also set TREE_READONLY.
	Change warn_write_strings to flag_const_strings.
	* c-decl.c, c-tree.h: Likewise.

Index: c-common.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-common.c,v
retrieving revision 1.28
diff -c -p -r1.28 c-common.c
*** c-common.c	1998/08/13 17:29:11	1.28
--- c-common.c	1998/08/14 23:29:12
*************** combine_strings (strings)
*** 298,304 ****
        value = make_node (STRING_CST);
        TREE_STRING_POINTER (value) = p;
        TREE_STRING_LENGTH (value) = length;
-       TREE_CONSTANT (value) = 1;
      }
    else
      {
--- 298,303 ----
*************** combine_strings (strings)
*** 313,320 ****
  
    /* Create the array type for the string constant.
       -Wwrite-strings says make the string constant an array of const char
!      so that copying it to a non-const pointer will get a warning.  */
!   if (warn_write_strings
        && (! flag_traditional  && ! flag_writable_strings))
      {
        tree elements
--- 312,320 ----
  
    /* Create the array type for the string constant.
       -Wwrite-strings says make the string constant an array of const char
!      so that copying it to a non-const pointer will get a warning.
!      For C++, this is the standard behavior.  */
!   if (flag_const_strings
        && (! flag_traditional  && ! flag_writable_strings))
      {
        tree elements
*************** combine_strings (strings)
*** 328,334 ****
      TREE_TYPE (value)
        = build_array_type (wide_flag ? wchar_type_node : char_type_node,
  			  build_index_type (build_int_2 (nchars - 1, 0)));
!   TREE_CONSTANT (value) = 1;
    TREE_STATIC (value) = 1;
    return value;
  }
--- 328,335 ----
      TREE_TYPE (value)
        = build_array_type (wide_flag ? wchar_type_node : char_type_node,
  			  build_index_type (build_int_2 (nchars - 1, 0)));
! 
!   TREE_READONLY (value) = TREE_CONSTANT (value) = ! flag_writable_strings;
    TREE_STATIC (value) = 1;
    return value;
  }
Index: c-decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-decl.c,v
retrieving revision 1.40
diff -c -p -r1.40 c-decl.c
*** c-decl.c	1998/07/30 10:38:08	1.40
--- c-decl.c	1998/08/14 23:29:12
*************** int mesg_implicit_function_declaration;
*** 498,504 ****
     to get extra warnings from them.  These warnings will be too numerous
     to be useful, except in thoroughly ANSIfied programs.  */
  
! int warn_write_strings;
  
  /* Nonzero means warn about pointer casts that can drop a type qualifier
     from the pointer target type.  */
--- 498,504 ----
     to get extra warnings from them.  These warnings will be too numerous
     to be useful, except in thoroughly ANSIfied programs.  */
  
! int flag_const_strings;
  
  /* Nonzero means warn about pointer casts that can drop a type qualifier
     from the pointer target type.  */
*************** c_decode_option (argc, argv)
*** 713,721 ****
    else if (!strcmp (p, "-Wno-long-long"))
      warn_long_long = 0;
    else if (!strcmp (p, "-Wwrite-strings"))
!     warn_write_strings = 1;
    else if (!strcmp (p, "-Wno-write-strings"))
!     warn_write_strings = 0;
    else if (!strcmp (p, "-Wcast-qual"))
      warn_cast_qual = 1;
    else if (!strcmp (p, "-Wno-cast-qual"))
--- 713,721 ----
    else if (!strcmp (p, "-Wno-long-long"))
      warn_long_long = 0;
    else if (!strcmp (p, "-Wwrite-strings"))
!     flag_const_strings = 1;
    else if (!strcmp (p, "-Wno-write-strings"))
!     flag_const_strings = 0;
    else if (!strcmp (p, "-Wcast-qual"))
      warn_cast_qual = 1;
    else if (!strcmp (p, "-Wno-cast-qual"))
Index: c-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-tree.h,v
retrieving revision 1.10
diff -c -p -r1.10 c-tree.h
*** c-tree.h	1998/07/06 21:53:21	1.10
--- c-tree.h	1998/08/14 23:29:12
*************** extern int warn_implicit;
*** 430,436 ****
     to get extra warnings from them.  These warnings will be too numerous
     to be useful, except in thoroughly ANSIfied programs.  */
  
! extern int warn_write_strings;
  
  /* Nonzero means warn about sizeof (function) or addition/subtraction
     of function pointers.  */
--- 430,436 ----
     to get extra warnings from them.  These warnings will be too numerous
     to be useful, except in thoroughly ANSIfied programs.  */
  
! extern int flag_const_strings;
  
  /* Nonzero means warn about sizeof (function) or addition/subtraction
     of function pointers.  */


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