This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Bye bye flag_const_strings
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Mark Mitchell <mark at codesourcery dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: 09 Feb 2006 15:50:57 +0100
- Subject: Re: Bye bye flag_const_strings
- References: <m3u0bcup0b.fsf@uniton.integrable-solutions.net> <Pine.LNX.4.64.0602062206270.16920@digraph.polyomino.org.uk> <m3mzh4umrz.fsf@uniton.integrable-solutions.net> <m3d5i0rmt5.fsf@uniton.integrable-solutions.net> <43E84F40.6010904@codesourcery.com> <43E8C162.1090903@redhat.com>
Jason Merrill <jason@redhat.com> writes:
| Mark Mitchell wrote:
| > Gabriel Dos Reis wrote:
| >
| >> ! ??? We should change the type of an expression depending on the
| > Missing "not" after "should".
| > Otherwise, I'm happy with the patch, but I think that Jason and
| > Nathan
| > should get a chance to vote, since we're removing an (deprecated)
| > extension. Historically, Jason has been the most conservative of the
| > three of us.
|
| I doubt anyone has used flag_const_strings in years. I won't miss it.
Thanks. This is the final version of the patch that passed
regtesting. There was a testsuite testing for -fconst-strings and its
negation.
A separate patch will address the -Wwrite-strings issue raised in a
parallel subthread.
-- Gaby
2006-02-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
* c-common.h (flag_const_strings): Don't declare.
* c-common.c (flag_const_strings): Remove.
* c.opt (fconst_strings): Remove.
* c-opts.c (c_common_handle_option): Remove <OPT_fconst_strings>.
<OPT_Wwrite_strings>: Don't set flag_const_strings.
(c_common_init_options): Don't set flag_const_strings.
* doc/invoke.texi (-fno-const-strings): Remove documentation.
cp/
2006-02-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
* typeck.c (string_conv_p): Don't test for flag_const_strings.
testsuite/
2006-02-09 Gabriel Dos Reis <gdr@integrable-solutions.net>
* g++.old-deja/g++.benjamin/15351-2.C: Likewise.
* g++.old-deja/g++.benjamin/15351-1.C: Remove.
*** c-common.c (revision 110802)
--- c-common.c (local)
*************** int flag_ms_extensions;
*** 261,271 ****
int flag_no_asm;
- /* Nonzero means give string constants the type `const char *', as mandated
- by the standard. */
-
- int flag_const_strings;
-
/* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
int flag_signed_bitfields = 1;
--- 261,266 ----
*************** fix_string_type (tree value)
*** 869,878 ****
nchars - 1, nchars_max, relevant_std);
}
! /* Create the array type for the string constant. flag_const_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.
The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
array type being the unqualified version of that type.
--- 864,877 ----
nchars - 1, nchars_max, relevant_std);
}
! /* Create the array type for the string constant. The ISO C++
! standard says that a string literal has type `const char[N]' or
! `const wchar_t[N]'. We use the same logic when invoked as a C
! front-end with -Wwrite-strings.
! ??? We should change the type of an expression depending on the
! state of a warning flag. We should just be warning -- see how
! this is handled in the C++ front-end for the deprecated implicit
! conversion from string literals to `char*' or `wchar_t*'.
The C++ front end relies on TYPE_MAIN_VARIANT of a cv-qualified
array type being the unqualified version of that type.
*************** fix_string_type (tree value)
*** 883,889 ****
e_type = wide_flag ? wchar_type_node : char_type_node;
i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
a_type = build_array_type (e_type, i_type);
! if (flag_const_strings)
a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
TREE_TYPE (value) = a_type;
--- 882,888 ----
e_type = wide_flag ? wchar_type_node : char_type_node;
i_type = build_index_type (build_int_cst (NULL_TREE, nchars - 1));
a_type = build_array_type (e_type, i_type);
! if (c_dialect_cxx() || warn_write_strings)
a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);
TREE_TYPE (value) = a_type;
*** c-opts.c (revision 110802)
--- c-opts.c (local)
*************** c_common_init_options (unsigned int argc
*** 225,231 ****
before passing on command-line options to cpplib. */
cpp_opts->warn_dollars = 0;
- flag_const_strings = c_dialect_cxx ();
flag_exceptions = c_dialect_cxx ();
warn_pointer_arith = c_dialect_cxx ();
--- 225,230 ----
*************** c_common_handle_option (size_t scode, co
*** 531,540 ****
break;
case OPT_Wwrite_strings:
! if (!c_dialect_cxx ())
! flag_const_strings = value;
! else
! warn_write_strings = value;
break;
case OPT_Weffc__:
--- 530,536 ----
break;
case OPT_Wwrite_strings:
! warn_write_strings = value;
break;
case OPT_Weffc__:
*************** c_common_handle_option (size_t scode, co
*** 652,661 ****
flag_conserve_space = value;
break;
- case OPT_fconst_strings:
- flag_const_strings = value;
- break;
-
case OPT_fconstant_string_class_:
constant_string_class_name = arg;
break;
--- 648,653 ----
*** c.opt (revision 110802)
--- c.opt (local)
*************** fconserve-space
*** 469,478 ****
C++ ObjC++
Reduce the size of object files
- fconst-strings
- C++ ObjC++
- Make string literals \"const char[]\" not \"char[]\"
-
fconstant-string-class=
ObjC ObjC++ Joined
-fconst-string-class=<name> Use class <name> for constant strings
--- 469,474 ----
*** cp/typeck.c (revision 110802)
--- cp/typeck.c (local)
*************** string_conv_p (tree totype, tree exp, in
*** 1472,1478 ****
{
tree t;
! if (! flag_const_strings || TREE_CODE (totype) != POINTER_TYPE)
return 0;
t = TREE_TYPE (totype);
--- 1472,1478 ----
{
tree t;
! if (TREE_CODE (totype) != POINTER_TYPE)
return 0;
t = TREE_TYPE (totype);
*** doc/invoke.texi (revision 110802)
--- doc/invoke.texi (local)
*************** in the following sections.
*** 175,181 ****
@item C++ Language Options
@xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
@gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol
! -fconserve-space -ffriend-injection -fno-const-strings @gol
-fno-elide-constructors @gol
-fno-enforce-eh-specs @gol
-ffor-scope -fno-for-scope -fno-gnu-keywords @gol
--- 175,181 ----
@item C++ Language Options
@xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
@gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol
! -fconserve-space -ffriend-injection @gol
-fno-elide-constructors @gol
-fno-enforce-eh-specs @gol
-ffor-scope -fno-for-scope -fno-gnu-keywords @gol
*************** earlier releases.
*** 1450,1466 ****
This option is for compatibility, and may be removed in a future
release of G++.
- @item -fno-const-strings
- @opindex fno-const-strings
- Give string constants type @code{char *} instead of type @code{const
- char *}. By default, G++ uses type @code{const char *} as required by
- the standard. Even if you use @option{-fno-const-strings}, you cannot
- actually modify the value of a string constant.
-
- This option might be removed in a future release of G++. For maximum
- portability, you should structure your code so that it works with
- string constants that have type @code{const char *}.
-
@item -fno-elide-constructors
@opindex fno-elide-constructors
The C++ standard allows an implementation to omit creating a temporary
--- 1450,1455 ----
*** testsuite/g++.old-deja/g++.benjamin/15351-1.C (revision 110802)
--- testsuite/g++.old-deja/g++.benjamin/15351-1.C (local)
***************
*** 1,28 ****
- // { dg-do run }
- // { dg-options "-fno-const-strings" }
- // 981203 bkoz
- // g++/15351 - test
-
- #include <assert.h>
-
- bool gtest;
-
- struct acapulco {
- acapulco(const char *) { gtest = false; }
- acapulco(char *) { gtest = true; }
- };
-
- void foo(void)
- {
- acapulco("some such string\n");
- }
-
- int main()
- {
- foo();
- if (!gtest)
- assert (0);
-
- return !gtest;
- }
-
--- 0 ----
*** testsuite/g++.old-deja/g++.benjamin/15351-2.C (revision 110802)
--- testsuite/g++.old-deja/g++.benjamin/15351-2.C (local)
***************
*** 1,28 ****
- // { dg-do run }
- // { dg-options "-fconst-strings" }
- // 981203 bkoz
- // g++/15351 + test
-
- #include <assert.h>
-
- bool gtest;
-
- struct acapulco {
- acapulco(const char *) { gtest = true; }
- acapulco(char *) { gtest = false; }
- };
-
- void foo(void)
- {
- acapulco("some such string\n");
- }
-
- int main()
- {
- foo();
- if (!gtest)
- assert (0);
-
- return !gtest;
- }
-
--- 0 ----