diff options
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) |