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: Patch: -Wtraditional condense multiple string concatenation warnings


 > From: Jeffrey A Law <law@cygnus.com>
 > 
 >   In message <200007172147.RAA10948@caip.rutgers.edu>you write:
 >   > The -Wtraditional warning about string concatenation will warn
 >   > multiple times for strings with multiple concatenations.  E.g.:
 >   > const char *foo = "hello " "hello " "hello " "hello " "hello ";
 >   > will warn four times.
 >   > 
 >   > On solaris2.7 where the EXTRA_SPECS string has dozens of bits joined
 >   > together, this gives us an annoying 70 warnings in gcc.c.
 >   > 
 >   > With the following patch, the number is reduced to a managable two.
 >   > This corresponds to the number of unique lines where concatenation
 >   > occurs.
 >   > 
 >   > Tested on solaris2.7.  Okay to install?
 >   > 
 >   > 		--Kaveh
 >   > 
 >   > 
 >   > 
 >   > 
 >   > 
 >   > 2000-07-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 >   > 
 >   > 	* c-parse.in (string): For -Wtraditional, warn about string
 >   > 	concatenation only once per line.
 > 
 > Don't you also need to verify that the filename hasn't changed too?
 > ie let's assume we had a concat at line 100 in file foo.c and also in
 > bar.h which was included by foo.c.
 > 
 > We should get two warnings, right?  I think with your patch we might
 > only get one.
 > 
 > jeff


Right, here's an updated patch which accounts file the filename too.

Tested on solaris2.7, okay to install?

		--Kaveh


2000-07-25  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* c-parse.in (string): For -Wtraditional, warn about string
	concatenation only once per line.

diff -rcp orig/egcs-CVS20000724/gcc/c-parse.in egcs-CVS20000724/gcc/c-parse.in
*** orig/egcs-CVS20000724/gcc/c-parse.in	Wed Jul 12 15:51:19 2000
--- egcs-CVS20000724/gcc/c-parse.in	Tue Jul 25 14:24:35 2000
*************** end ifobjc
*** 733,742 ****
  string:
  	  STRING
  	| string STRING
! 		{ $$ = chainon ($1, $2);
  ifc
! 		  if (warn_traditional && !in_system_header)
! 		    warning ("Use of ANSI string concatenation");
  end ifc
  		}
  	;
--- 733,753 ----
  string:
  	  STRING
  	| string STRING
! 		{
  ifc
!                   static int last_lineno = 0;
!                   static const char *last_input_filename = 0;
! end ifc
!                   $$ = chainon ($1, $2);
! ifc
! 		  if (warn_traditional && !in_system_header
! 		      && (lineno != last_lineno || !last_input_filename ||
! 			  strcmp (last_input_filename, input_filename)))
! 		    {
! 		      warning ("traditional C rejects string concatenation");
! 		      last_lineno = lineno;
! 		      last_input_filename = input_filename;
! 		    }
  end ifc
  		}
  	;

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