[cfe-dev] Wrong diagnostic for ternary operator
Jeroen Ruigrok van der Werven
asmodai at in-nomine.org
Wed Jul 25 22:27:08 PDT 2007
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.
--
Jeroen Ruigrok van der Werven <asmodai(-at-)in-nomine.org> / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
The last word in a chronicle is never set down...
More information about the cfe-dev
mailing list