This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: question regarding new warning
- From: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: gcc Mailing List <gcc at gcc dot gnu dot org>, Andrew Haley <aph at redhat dot com>, Florian Weimer <fweimer at redhat dot com>
- Date: Thu, 27 Mar 2014 19:37:07 -0300
- Subject: Re: question regarding new warning
- Authentication-results: sourceware.org; auth=none
- References: <CAESRpQCxV22=h1oXRB4Q6-ywWOSt4aQ9o0Tkj38Bo_DTfiOjbg at mail dot gmail dot com>
On Thu, Mar 27, 2014 at 6:48 AM, Manuel López-Ibáñez
<lopezibanez@gmail.com> wrote:
> On 27/03/14 09:52, Florian Weimer wrote:> On 03/27/2014 08:44 AM,
> Andrew Haley wrote:
>>
>>> On 03/26/2014 03:05 PM, Daniel Gutson wrote:
>>>
>>>> assigning a negative literal to an unsigned variable issues no warning:
>>>>
>>>>
>>>> unsigned int x;
>>>> x =- 4;
>>>>
>>>> This is specially important in typos when -= was intended instead of =-
>>>>
>>>> Would be acceptable if I add a new warning to handle this, i.e.
>>>> -Wnegative-to-unsigned
>>>> or alike?
>>>
>>> Assigning a negative literal to an unsigned variable is well-defined
>>> standard C. Is it really appropriate to warn for correct code?
>>
>> Yes, this warning needs to take whitespace into account. But then, I suppose
>> it would be fine.
>>
>
> This is already warned by -Wconversion/-Wsign-conversion since at
> least GCC 4.6 (but I think probably since GCC 4.3):
>
> test.c: In function 'foo':
> test.c:4:8: warning: negative integer implicitly converted to unsigned
> type [-Wsign-conversion]
> x =- 4;
> ^
I didn't have such warning in my radar. Good one!
>
> There are some known bugs in -Wconversion and nobody working on them,
> so if you are still interested in helping, I can give you some hints
> on where your help will be very welcome.
Could you please go ahead and show me the failing cases?
I only worked in the backend, but I'd like to take a look to the front-end.
There's also all the other commenters of my post regarding the =- and
=+ looking-like operators, which should take ws into account.
>
> Cheers,
>
> Manuel.
--
Daniel F. Gutson
Chief Engineering Officer, SPD
San Lorenzo 47, 3rd Floor, Office 5
Córdoba, Argentina
Phone: +54 351 4217888 / +54 351 4218211
Skype: dgutson