This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 4.3.0, -Wconversion: assignment-by operators for shorter types
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "Andriy Gapon" <avg at icyb dot net dot ua>
- Cc: "Andrew Pinski" <pinskia at gmail dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 30 Jul 2008 10:47:02 +0200
- Subject: Re: gcc 4.3.0, -Wconversion: assignment-by operators for shorter types
- References: <483AF557.8050603@icyb.net.ua> <6c33472e0805270350p62d8f334v8e881e361fee4bb0@mail.gmail.com> <483C531A.5060507@icyb.net.ua> <de8d50360805271148u10525605ib84afa5c7957b2f7@mail.gmail.com> <483C5948.1060209@icyb.net.ua> <de8d50360805271200h3ced4e88n7cec1258cb0a7157@mail.gmail.com> <483D006D.2040701@icyb.net.ua>
2008/5/28 Andriy Gapon <avg@icyb.net.ua>:
> on 27/05/2008 22:00 Andrew Pinski said the following:
>>
>> On Tue, May 27, 2008 at 11:56 AM, Andriy Gapon <avg@icyb.net.ua> wrote:
>>>
>>> Thank you for the explanation! I didn't realize the difference.
>>>
>>> OTOH, do you think that those arithmetic warnings are practical (as
>>> opposed
>>> to being correct)?
>>
>> I think so as the short int case has a defined overflow of the signed
>> short type that is SHRT_MAX + 1 is defined while INT_MAX + 1 is not.
>
> I still feel like disagreeing.
> Consider this:
> *************
> int main()
> {
> short short_x;
>
> short_x = short_x + 1;
> short_x += 1;
> short_x++;
> ++short_x;
>
> return 0;
> }
> *************
>
> $ gcc43 -Wconversion test-conv2.c -o test-conv
> test-conv2.cc: In function 'int main()':
> test-conv2.cc:5: warning: conversion to 'short int' from 'int' may alter its
> value
> test-conv2.cc:6: warning: conversion to 'short int' from 'int' may alter its
> value
>
> I thought that in C all 4 forms were equivalent and this was purely a style
> choice. Now they are different.
>
Please open a bug report (http://gcc.gnu.org/bugs.html) with this
issue and add manu@gcc.gnu.org to the CC list. Otherwise this will be
forgotten.
Cheers,
Manuel.