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]

Re: -pedantic, string length (was: Re: Changes to gcc.c (display_help))


 > From: "Joseph S. Myers" <jsm28@cam.ac.uk>
 > 
 > Kaveh R. Ghazi wrote:
 > 
 > > +  if (pedantic && nchars > 508)
 > > +    pedwarn ("string length %d is greater than ANSI C maximum 508", nchars);
 > 
 > The value - after concatenation but in my reading excluding the added NUL
 > - is 509 in C89 and 4095 in C99 and flag_isoc99 should be taken account of
 > accordingly.  My best interpretation of the standard wording is that this
 > is meant to refer to source multibyte characters before conversion to an
 > array of char or wchar_t; but multibyte correctness for this warning can
 > probably be attended to when full support for multibyte source and \u
 > escapes is implemented.  While in this part of the compiler, a C89-only
 > -pedantic warning for concatenating ordinary and wide string literals
 > would make sense.
 > 
 > The requirement is actually to translate and execute at least one
 > program containing a string of length 509 or 4095 (along with the
 > other minimum limits) rather than to reject longer strings - a
 > footnote discourages fixed translation limits - but having such a
 > -pedantic warning, using the appropriate limit for the standard
 > version selected, seems reasonable.  Saying "minimum limit" rather
 > than "maximum" might more accurately reflect the standards.  (This
 > is a limit which has actually been included in compilers, so the
 > warning is useful.)



Okay I made a wording change along with the code change to honor
flag_isoc99, and changed the c89 case to use 509.  How's this?


2000-06-28  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-common.c (combine_strings): Emit a pedantic warning when a
	string length is greater than the minimum ANSI C is required
	to support.

diff -rup ../egcs-CVS20000628/gcc/c-common.c egcs-CVS20000628/gcc/c-common.c
--- ../egcs-CVS20000628/gcc/c-common.c	Wed Jun 28 09:37:11 2000
+++ egcs-CVS20000628/gcc/c-common.c	Wed Jun 28 10:42:56 2000
@@ -291,6 +291,7 @@ combine_strings (strings)
   int wide_flag = 0;
   int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
   int nchars;
+  const int nchars_max = flag_isoc99 ? 4095 : 509;
 
   if (TREE_CHAIN (strings))
     {
@@ -369,6 +370,10 @@ combine_strings (strings)
 
   /* Compute the number of elements, for the array type.  */
   nchars = wide_flag ? length / wchar_bytes : length;
+
+  if (pedantic && nchars > nchars_max)
+    pedwarn ("string length `%d' is greater than the minimum length `%d' ANSI C is required to support",
+	     nchars, nchars_max);
 
   /* Create the array type for the string constant.
      -Wwrite-strings says make the string constant an array of const char

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