This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix -Wconversion (PR c++/34198)
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 23 Nov 2007 15:39:26 +0100
- Subject: Re: [PATCH] Fix -Wconversion (PR c++/34198)
- References: <20071123120156.GE5451@devserv.devel.redhat.com>
On 23/11/2007, Jakub Jelinek <jakub@redhat.com> wrote:
>
> I have tried to use get_unwidened as well, but that results in some warnings
> which are desirable to be omitted. Say for:
> signed char sc;
> ...
> signed char i = (int) (unsigned short int) sc;
> when using expr = get_unwidened (expr, expr) instead of get_narrower
> it doesn't warn, eventhough the implicit conversion from (int) (ushort) sc
> to (signed char) really can change the value. Consider sc = -1, here
> (int) (unsigned short int) sc
> is 0xffff, while (signed char) 0xffff is -1. get_unwidened does that,
> because the outermost widening conversion is skipped over and then
> there are just conversions with equal precision. With get_narrower
> it does the right thing.
Using expr = get_unwidened (expr, TREE_TYPE (expr)) or expr =
get_unwidened (expr, 0) passes this and all your testcases. And it
makes the code much simpler and compact. Are you sure about this?
Cheers,
Manuel.