[cfe-dev] Wrong diagnostic for ternary operator

Steve Naroff snaroff at apple.com
Thu Jul 26 07:41:06 PDT 2007


On Jul 26, 2007, at 5:54 AM, Neil Booth wrote:

> Jeroen Ruigrok van der Werven wrote:-
>
>> This is a simplification of some code I let clang loose on:
>>
>> #include <stdio.h>
>>
>> int
>> main(void) {
>>         int test = 0;
>>
>>         printf("Type is %s\n", (test >= 1 ? "short" : "char"));
>>
>>         return (0);
>> }
>>
>> It comes up with a diagnostic that's misleading upon first read.
>>
>> t.c:7:36: error: incompatible operand types ('char *' and 'char *')
>>         printf("Type is %s\n", (test >= 1 ? "short" : "char"));
>>                                           ^ ~~~~~~~   ~~~~~~
>> 1 diagnostic generated.
>>
>> I think the average developer will wonder why "short" and "char" are
>> incompatible, especially since the tildes draw attention to that.  
>> The accent
>> circumflex gets lost in the noise.
>>
>> The code in question used this to toggle which text to use in a %s  
>> argument to
>> a printf() call and is quite valid.
>
> I'd guess operand decay isn't happening.
>

The bug was more primitive...I was missing a return statement.

There is still a FIXME (need to return the "composite" type).

snaroff

> Neil.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list