Thanks for explanation and help

But this leave me with the conclusion that one of the following must be wrong:

signed char xi;

xi = (int) (unsigned short int) sc; /* testcase NO WARNING - think this is bug*/ xi = (long) (unsigned short int) sc; /* warning: conversion to 'signed char' from 'short unsigned int' may alter its value - correct*/

Following your logic, (long).... appears to be wrong. Yet for i686 the first case (int)..... generates PASS with expected warning and that would seem similar.

So I'm still completely stuck knowing how I can patch testcase correctly for AVR or post a bug.

best regards
Andy


Manuel López-Ibáñez wrote:
2008/5/20 Andy H <[EMAIL PROTECTED]>:
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.

Reply via email to