This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix -Wconversion (PR c++/34198)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]