This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wconversion bug in g++-4.3?
On Fri, Nov 23, 2007 at 12:02:31AM +0100, Manuel López-Ibáñez wrote:
> For this testcase:
>
> void g(const unsigned char b)
> {
> unsigned short c = b & 0xff;
> }
>
> we get:
>
> wconversion-3.c:3: warning: conversion to 'unsigned char' from 'int'
> may alter its value
> wconversion-3.c:3: warning: conversion to 'short unsigned int' from
> 'int' may alter its value
The type of (b & 0xff) is int. However, the value is bounded, and must be
in 0x00 to 0xff, so the conversion will not alter the value. I don't know
if the warning code is structured to take the value range into account.
In any case, the double warning is odd.