This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++ patch] Warn for assignment from int to bool
- To: Erik Mouw <J dot A dot K dot Mouw at its dot tudelft dot nl>
- Subject: Re: [c++ patch] Warn for assignment from int to bool
- From: Jason Merrill <jason at cygnus dot com>
- Date: 01 Mar 2000 13:40:32 -0800
- Cc: gcc-patches at gcc dot gnu dot org, martin at loewis dot home dot cs dot tu-berlin dot de, C dot J dot Veenman at its dot tudelft dot nl
- References: <200002282247.XAA27874@duteinh.et.tudelft.nl>
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)