This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Implicit type conversion check
- From: "Manuel LÃpez-IbÃÃez" <lopezibanez at gmail dot com>
- To: "Pierre Chatelier" <pierre dot chatelier at club-internet dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 30 Nov 2006 11:09:50 +0000
- Subject: Re: Implicit type conversion check
- References: <1A18C079-9A21-496A-A392-9BAA36036A34@club-internet.fr>
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.