This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH to further improve diagnostic for -Wsign-compare (PR c/81417)
- From: Marek Polacek <polacek at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Mon, 31 Jul 2017 18:05:12 +0200
- Subject: Re: C PATCH to further improve diagnostic for -Wsign-compare (PR c/81417)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B24D32DA0CA
- References: <20170731141452.GR3397@redhat.com> <b47d9cf4-7496-1edf-2fa6-ea8d30016327@gmail.com>
On Mon, Jul 31, 2017 at 09:54:03AM -0600, Martin Sebor wrote:
> On 07/31/2017 08:14 AM, Marek Polacek wrote:
> > This patch improves the diagnostic of -Wsign-compare for ?: by also printing
> > the types, similarly to my recent patch. But we can do even better here if we
> > actually point to the operand in question, so I passed the locations of the
> > operands from the parser. So instead of
> >
> > x.c:8:16: warning: signed and unsigned type in conditional expression [-Wsign-compare]
> > return x ? y : -1;
> > ^
> > you'll now see:
> >
> > x.c:8:18: warning: operand of conditional expression changes signedness: 'int' to 'unsigned int' [-Wsign-compare]
> > return x ? y : -1;
> > ^
>
> I like that this is more informative than the last warning you
> committed for this bug: it says what type the operand is converted
> to. The last one only shows what the types of the operands are but
> leaves users guessing as to what that might mean (integer promotion
> rules are often poorly understood). Where the last warning prints
>
> comparison of integer expressions of different signedness: ‘int’ and
> ‘unsigned int’
>
> it would be nice to go back and add this detail to it as well, and
> have it print something like this instead:
>
> comparison of integer expressions of different signedness changes type of
> the second operand from ‘int’ to ‘unsigned int’
>
> Where constant expressions are involved it would also be helpful
> to show the result of the conversion. For instance:
>
> comparison between ‘int’ and ‘unsigned int’ changes the value of the
> second operand from ‘-1’ to ‘4294967296’
Hmm, interesting. I could do that. How do other people feel about this?
Marek