This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH RFA: C++: Avoid inappropriate -Wsign-compare warnings
- From: Ian Lance Taylor <iant at google dot com>
- To: Paolo Bonzini <paolo dot bonzini at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org, jason at redhat dot com
- Date: Thu, 18 Jun 2009 14:27:29 -0700
- Subject: Re: PATCH RFA: C++: Avoid inappropriate -Wsign-compare warnings
- References: <m33a9ysjqp.fsf@google.com> <4A39E447.8090109@gmail.com>
Paolo Bonzini <paolo.bonzini@gmail.com> writes:
> Ian Lance Taylor wrote:
>> Here is a better patch to address the problem described in some detail
>> in http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01393.html . In this
>> patch I simply set TREE_NO_WARNING for cases where we are using a
>> builtin operator and we have cast an unsigned enum type to a signed
>> integral type. Then I test TREE_NO_WARNING before calling
>> warn_sign_compare.
>
> I'm wondering what happens for unsigned enums whose biggest member is
>>= 2^31. Maybe you have to test TYPE_PRECISION in
> avoid_sign_compare_warnings?
An enum whose biggest member is that large will not be cast to a signed
int, since that would not work. See type_promotes_to in cp/cvt.c. So
this patch won't change the behaviour, which is to say that you will get
a warning if an instance of the enum type is compared with a signed int
and not if compared with an unsigned int.
Ian