Implicit type conversion check
Manuel López-Ibáñez
lopezibanez@gmail.com
Thu Nov 30 11:50:00 GMT 2006
On 30/11/06, Pierre Chatelier <pierre.chatelier@club-internet.fr> wrote:
> Hello,
>
> I am sorry if it is some usual request, but I could not find recent
> information about that, neither in the mailing list nor in the FAQ.
> Is there any plan to enforce warnings about implicit type conversion ?
>
I am happy to inform you that there is [1].
Part of this it's already on mainline, you could download it [2] and
install it [3] in order to test it. Comments are welcome.
[1] http://gcc.gnu.org/wiki/NewWconversion
[2] http://gcc.gnu.org/svn.html
[3] http://gcc.gnu.org/install
> the -W option implies some checks about _comparison_ between signed
> and unsigned, but nothing seems available for _affectation_.
affectation ?
> In the snippet below, only line 9 can trigger a warning.
>
> 1 void function(float f, double d, int i, unsigned int u)
> 2 {
> 3 f = d; /* potential loss of information */
warned by Wconversion
> 4 i = f; /* ~ */
likewise
> 5 i = d; /* ~ */
likewise
> 6 u = i; /* may overflow */
likewise
> 7 i = u; /* may overflow */
likewise.
> 8
> 9 i = (i<u) ? u : i; /* this comparison *does* trigger a
> warning */
if you use Wconversion you will get another warning here, since the
value of the second u is converted to signed int so you may end up
with a negative number in i even if u and i are positive numbers.
Cheers,
Manuel.
More information about the Gcc
mailing list