This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Whats going on with the conversion warning?


2008/5/20 Andy H <hutchinsonandy@aim.com>:
>
> I came across this odd issue with testsuite test Wconversion-5.c and AVR
> target.
> I should get warning going from a unsigned value that is wider than signed
> result.
>

Yes. You should also get a warning from a unsigned value converted to
a same-width signed type.

> void foo(void)
> {
>  signed char sc;
>  signed char xi;
>
>  xi =  (int) (unsigned short int) sc;    /* testcase NO WARNING - think this
> is bug*/

I may be wrong but I think (unsigned short int) sc is zero-extended,
then (int)(unsigned short int) sc is again zero extended. This means
that the complete conversion results in an integer value that when
converted to signed char gives back the original signed char. So the
assignment is actually equivalent to xi = sc. Ergo, no conversion
warning.

>  xi =  (unsigned short int) sc;   /* NO WARNING - think this is bug*/

The same applies here. Zero-extending to a wider type and then
conversion to the original type does not change the value. So now
warning. (That is, Wconversion can see whether the casts actually
affect the result or not.)

So I think this is not a bug. There are bugs in Wconversion, nonetheless.

http://gcc.gnu.org/PR35635
http://gcc.gnu.org/PR35701
http://gcc.gnu.org/PR34389
http://gcc.gnu.org/PR35852

Cheers,

Manuel.


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