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: [c++ patch] Warn for assignment from int to bool


This patch introduces too many warnings from the g++ testsuite.  I removed
one case of useless warnings (initialization from '1' or '0') by adding an
int_fits_type_p check, but we still generate bogus warnings for conversions
from class type (such as the STL _Bit_reference).  Here's my tweaked
version of the patch; please fix the _Bit_reference problem, and deal with
any testsuite failures introduced (either by marking the errors as
expected, fixing the compiler, or fixing the testcase code)

2000-03-01  Cor Veenman  <C.J.Veenman@its.tudelft.nl>

	* typeck.c (convert_for_assignment): Warn about conversion to bool.

Index: typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.252
diff -c -p -r1.252 typeck.c
*** typeck.c	2000/03/01 17:16:35	1.252
--- typeck.c	2000/03/01 21:23:19
*************** convert_for_assignment (type, rhs, errty
*** 6487,6492 ****
--- 6487,6502 ----
        else
  	cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype);
      }
+   /* And warn about assigning non-BOOLEAN_TYPE to BOOLEAN_TYPE.  */
+   else if (coder != BOOLEAN_TYPE && codel == BOOLEAN_TYPE
+ 	   && ! int_fits_type_p (rhs, type))
+     {
+       if (fndecl)
+ 	cp_warning ("`%T' used for argument %P of `%D'",
+ 		    rhstype, parmnum, fndecl);
+       else
+ 	cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype);
+     }
    /* And warn about assigning a negative value to an unsigned
       variable.  */
    else if (TREE_UNSIGNED (type) && codel != BOOLEAN_TYPE)

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