gcc 4.3.0, -Wconversion: assignment-by operators for shorter types
Andriy Gapon
avg@icyb.net.ua
Tue May 27 18:30:00 GMT 2008
on 27/05/2008 13:50 Manuel López-Ibáñez said the following:
> Please, open a bug report: http://gcc.gnu.org/bugzilla/
Manuel,
I looked through open GCC bugs and it seems that the following bugs are
very similar to what I report:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34389
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32643
Should I still open a new one or maybe it's better to follow up on one
of those two.
And just in case, here's a better description of what I am reporting
(demonstration by comparison):
**********************
int main()
{
int int_x;
int int_y;
short short_x;
short short_y;
short_x += short_y;
short_x = short_x + short_y;
int_x += int_y;
int_x = int_x + int_y;
return 0;
}
**********************
$ g++ -Wconversion test-conv.cc -o test-conv
test-conv.cc: In function ‘int main()’:
test-conv.cc:8: warning: conversion to ‘short int’ from ‘int’ may alter
its value
test-conv.cc:9: warning: conversion to ‘short int’ from ‘int’ may alter
its value
$ g++ -dumpversion
4.3.0
> 2008/5/26 Andriy Gapon <avg@icyb.net.ua>:
>> If I write something like the following:
>> uint8_t x;
>> uint8_t y;
>> x ^= y;
>>
>> and compile with gcc 4.3.0 with -Wconversion option, then I get the
>> following warning:
>> warning: conversion to 'unsigned char' from 'int' may alter its value
>> [-Wconversion]
>>
>> While technically this warning is correct (because x and y are
>> implicitly advanced to "int"before actual xor operation), it seems that
>> it doesn't make much practical sense.
>>
>> I think that this applies to all "assignment-by" operators working on
>> types shorter than int.
>>
>> OTOH, proper implementation should be smart enough to warn about the
>> following:
>> uint8_t x;
>> uint16_t y;
>> x ^= y;
>>
>>
>> --
>> Andriy Gapon
>>
--
Andriy Gapon
More information about the Gcc
mailing list