[cfe-commits] [Patch] Remove checking signs of operands of conditional operator from -Wsign-compare
Richard Trieu
rtrieu at google.com
Thu Jul 14 16:24:45 PDT 2011
On Thu, Jul 14, 2011 at 4:11 PM, Chandler Carruth <chandlerc at google.com>wrote:
> On Thu, Jul 14, 2011 at 4:01 PM, Richard Trieu <rtrieu at google.com> wrote:
>
>> On Thu, Jul 14, 2011 at 3:53 PM, Chandler Carruth <chandlerc at google.com>wrote:
>>
>>> On Thu, Jul 14, 2011 at 3:35 PM, Richard Trieu <rtrieu at google.com>wrote:
>>>
>>>> Currently, -Wsign-compare will warn if conditional operands differ in
>>>> signedness. This patch will move this warning to -Wmixed-sign-conditional
>>>
>>>
>>> Why not -Wsign-conversion ? Just wondering why we need a separate flag
>>> here.
>>>
>> -Wsign-conversion has a separate warning that will override this one.
>> Essentially, the conditional statement can have only have one type, so if
>> the operands are of different signs, one will be forced to convert, which
>> throws the warning. Here's an example:
>>
>> void f(unsigned int u, int i) {
>> (void) (true ? u : i);
>> }
>>
>> clang -Wsign-conversion
>> warning: operand of ? changes signedness: 'int' to 'unsigned int'
>> [-Wsign-conversion]
>> (void) (true ? u : i);
>> ~ ^
>>
>
> Ah, cool
>
>
>> clang -Wmixed-sign-conditional
>> warning: operands of ? are integers of different signs:
>> 'unsigned int' and 'int' [-Wmixed-sign-conditional]
>> (void) (true ? u : i);
>> ^ ~ ~
>>
>
> So what's the motivation for being able to get *just* these warnings out?
> The only bug I'm aware of was specific to -Wsign-compare warning on this
> construct in a compile that didn't use -Wsign-conversion, and so expected
> the code to compile without warnings. If -Wsign-conversion already catches
> this, it would seem to me that that's sufficient?
>
The main motivation is to make -Wsign-compare only about checking signs
during comparisons. Since the operands of the conditional operator aren't
compared, it seems out of place to check it there.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110714/aa08f095/attachment.html>
More information about the cfe-commits
mailing list