diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 2006-01-29 03:30:47 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2006-01-29 03:30:47 +0000 |
commit | 89a42ac8a1c85ee240df92c7ccd0c973bc95a24c (patch) | |
tree | d4a553c734fb691a872f7a7a3de2bf60d8a30c00 /gcc/c-common.c | |
parent | 0f7868fed2674fab28566ce47b388c5a48a9c8aa (diff) | |
download | gcc-89a42ac8a1c85ee240df92c7ccd0c973bc95a24c.zip gcc-89a42ac8a1c85ee240df92c7ccd0c973bc95a24c.tar.gz gcc-89a42ac8a1c85ee240df92c7ccd0c973bc95a24c.tar.bz2 |
c.opt: Add -W(no-)overlength-strings.
gcc:
* c.opt: Add -W(no-)overlength-strings.
* doc/invoke.texi: Document it.
* c-opts.c (c_common_handle_option): -pedantic implies
-Woverlength-strings, if not explicitly disabled already.
(c_common_post_options): -Woverlength-strings defaults to off, and
is always off for C++.
* c-common.c (fix_string_type): Issue warning about strings longer
than is portable only if warn_overlength_strings. Rearrange code
a little for clarity.
* configure.in: Check for -Wno-overlength-strings as well before
enabling -pedantic in stage 1.
* Makefile.in (STRICT2_WARN): Add -Wno-overlength-strings.
(gcc.o-warn, insn-automata.o-warn, build/gencondmd.o-warn): Delete.
* genconditions.c (write_header, write_one_condition)
(write_conditions, write_writer): Consolidate very long strings
that were broken up to fit in C89 portable limit. Don't use
printf when fputs will do.
gcc/testsuite:
* gcc.dg/Woverlength-strings.c
* gcc.dg/Woverlength-strings-pedantic-c89.c
* gcc.dg/Woverlength-strings-pedantic-c89-no.c
* gcc.dg/Woverlength-strings-pedantic-c99.c
* gcc.dg/Woverlength-strings-pedantic-c99-no.c: New tests.
==================================================================
From-SVN: r110360
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index fe99dfb..5be3363 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -844,7 +844,6 @@ fix_string_type (tree value) { const int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT; const int wide_flag = TREE_TYPE (value) == wchar_array_type_node; - const int nchars_max = flag_isoc99 ? 4095 : 509; int length = TREE_STRING_LENGTH (value); int nchars; tree e_type, i_type, a_type; @@ -852,11 +851,24 @@ fix_string_type (tree value) /* Compute the number of elements, for the array type. */ nchars = wide_flag ? length / wchar_bytes : length; - if (pedantic && nchars - 1 > nchars_max && !c_dialect_cxx ()) - pedwarn ("string length %qd is greater than the length %qd ISO C%d compilers are required to support", - nchars - 1, nchars_max, flag_isoc99 ? 99 : 89); + /* C89 2.2.4.1, C99 5.2.4.1 (Translation limits). The analogous + limit in C++98 Annex B is very large (65536) and is not normative, + so we do not diagnose it (warn_overlength_strings is forced off + in c_common_post_options). */ + if (warn_overlength_strings) + { + const int nchars_max = flag_isoc99 ? 4095 : 509; + const int relevant_std = flag_isoc99 ? 99 : 90; + if (nchars - 1 > nchars_max) + /* Translators: The %d after 'ISO C' will be 90 or 99. Do not + separate the %d from the 'C'. 'ISO' should not be + translated, but it may be moved after 'C%d' in languages + where modifiers follow nouns. */ + pedwarn ("string length %qd is greater than the length %qd " + "ISO C%d compilers are required to support", + nchars - 1, nchars_max, relevant_std); + } - e_type = wide_flag ? wchar_type_node : char_type_node; /* 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++, @@ -868,6 +880,7 @@ fix_string_type (tree value) construct the matching unqualified array type first. The C front end does not require this, but it does no harm, so we do it unconditionally. */ + 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) |