[cfe-dev] Wrong diagnostic for ternary operator

Neil Booth neil at daikokuya.co.uk
Thu Jul 26 05:54:15 PDT 2007


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.

Neil.



More information about the cfe-dev mailing list