Patch from the Wcoercion Project
http://gcc.gnu.org/wiki/Wcoercion#Background
This patch adds most of the new functionality of Wconversion: warn for implicit
conversions that may alter a value. This includes conversions between
real and integer, like abs (x) when x is double; conversions between
signed and unsigned, like unsigned ui = -1; and conversions to smaller
types, like sqrtf (M_PI). Do not warn for explicit casts like abs
((int) x) and ui = (unsigned) -1, or if the value is not changed by
the conversion like abs (2.0).
Note1: testcases are not added to c++ in this patch because: (1) there
is already a partial implementation of this in c++ with its own
testcases (2) the partial implementation warns for abs(2.0),
conflicting with my own implementation. The next patch will address
these issues.
Bootstrapped and tested with --enable-languages=all for trunk revision
1118055 on i686-pc-linux-gnu
:ADDPATCH c/c++:
2006-11-05 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* c-common.c (conversion_warning): New.
(convert_and_check): Call conversion_warning unless there is an
overflow warning.
* doc/invoke.texi (-Wconversion): Update description.
testsuite/
2006-11-05 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* gcc.dg/Wconversion-integer.c: New. Supersedes
Wconversion-negative-constants.c
* gcc.dg/Wconversion-real.c: New.
* gcc.dg/Wconversion-real-integer.c: New.
* gcc.dg/Wconversion-negative-constants.c: Deleted.
* g++.dg/warn/Wconversion1.C: Modified.