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]
Other format: [Raw text]

C++ PATCH: Fix -Wsign-compare regression on mainline


This patch fixes the -Wsign-compare regression that Gerald noticed on
the mainline.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-07-10  Mark Mitchell  <mark@codesourcery.com>

	* typeck.c (build_binary_op): Do not warn about signed
	vs. unsigned comparisons in the bodies of templates.

2003-07-11  Mark Mitchell  <mark@codesourcery.com>

	* g++.dg/warn/Wsign-compare-1.C: New test.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.479
diff -c -5 -p -r1.479 typeck.c
*** cp/typeck.c	10 Jul 2003 16:47:48 -0000	1.479
--- cp/typeck.c	11 Jul 2003 08:04:12 -0000
*************** build_binary_op (enum tree_code code, tr
*** 3441,3451 ****
  	  converted = 1;
  	  resultcode = xresultcode;
  	}
  
        if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
! 	  && warn_sign_compare)
  	{
  	  int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
  	  int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
  
  	  int unsignedp0, unsignedp1;
--- 3441,3454 ----
  	  converted = 1;
  	  resultcode = xresultcode;
  	}
  
        if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
! 	  && warn_sign_compare
! 	  /* Do not warn until the template is instantiated; we cannot
! 	     bound the ranges of the arguments until that point.  */
! 	  && !processing_template_decl)
  	{
  	  int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
  	  int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
  
  	  int unsignedp0, unsignedp1;
Index: testsuite/g++.dg/warn/Wsign-compare-1.C
===================================================================
RCS file: testsuite/g++.dg/warn/Wsign-compare-1.C
diff -N testsuite/g++.dg/warn/Wsign-compare-1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/Wsign-compare-1.C	11 Jul 2003 08:04:44 -0000
***************
*** 0 ****
--- 1,6 ----
+ // { dg-options "-Wsign-compare" }
+ 
+ extern unsigned u;
+ 
+ template<class F>
+ int f() { return u > 1; }


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