casey@GAUSS.LLNL.GOV (Casey Leedom) (01/08/90)
[[If you develop a fix for this, I'd appreciate hearing about it. Thanks
for your attention.]]
VERSION:
GCC 1.34 and GCC 1.36
CLIENT MACHINE and OPERATING SYSTEM:
GCC 1.34; Alliant FX/8; Alliant Concentrix 5.0.0
GCC 1.36; Vax-11/785; 4.3BSD with 4.3-tahoe networking
GCC 1.36; Sun 3/280; Sun OS 3.5
SYNOPSIS:
GCC incorrectly compiles ``"..." == 0 ? exp1 : exp2'' into ``exp1''.
REPEAT BY:
main()
{
char *s;
int i;
/* CORRECT:
* the following is compiled into ``i = 0'' (false)
*/
i = ("all" == 0);
printf("i = %d\n", i);
/* WRONG:
* the following is compiled into ``s = "true"''
*/
s = (("all" == 0) ? "true" : "false");
printf("s = \"%s\"\n", s);
/* CORRECT:
* the following is compiled into ``s = "false"''
*/
if ("all" == 0)
s = "true";
else
s = "false";
printf("s = \"%s\"\n", s);
}
SAMPLE FIX:
I don't know the compiler well enough to be able to specify a fix,
but I do notice one significant difference between the handling of
the boolean expression in the "?:" operator and if statement: on
line 984 of c-parse.y the if statement boolean expression is passed
directly to truthvalue_conversion(), while on line 2631 of
c-typeck.c in the function build_conditional_expr(), the "?:"
operator boolean expression is passed through default_conversion()
whose result is then passed to truthvalue_conversion(). What
significance this may have, I have no idea.