NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/44253: gcc's cpp mishandles ?: operator precedence



>Number:         44253
>Category:       toolchain
>Synopsis:       gcc's cpp mishandles ?: operator precedence
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 20 05:40:00 +0000 2010
>Originator:     David A. Holland
>Release:        NetBSD 5.99.41 (20101130)
>Organization:
>Environment:
System: NetBSD macaran 5.99.41 NetBSD 5.99.41 (MACARAN) #3: Tue Nov 30 21:52:01 
EST 2010 dholland@macaran:/usr/src/sys/arch/amd64/compile/MACARAN amd64
Architecture: x86_64
Machine: amd64
>Description:

cpp seems to mishandle nested ?: in #if expressions.

>How-To-Repeat:

  --- snip ---
#include <stdio.h>

int d =
#if 2 > 1 ? 0 : 0 ? 1 : 1
1
#else
0
#endif
;

int e =
#if (2 > 1 ? 0 : 0) ? 1 : 1
1
#else
0
#endif
;

int f =
#if 2 > 1 ? 0 : (0 ? 1 : 1)
1
#else
0
#endif
;


int
main()
{
        int a, b, c;

        a = 2 > 1 ? 0 : 0 ? 1 : 1;
        b = (2 > 1 ? 0 : 0) ? 1 : 1;
        c = 2 > 1 ? 0 : (0 ? 1 : 1);

        printf("%d %d %d\n", a, b, c);
        printf("%d %d %d\n", d, e, f);

        return 0;
}
   --- snip ---

Running this produces the output

0 1 0
1 1 0

That is, the cpp behavior is not consistent with the behavior of the C
expression parser.

According to operator(7) the C expression parser is correct and cpp is
broke.

>Fix:

apply a large hammer?



Home | Main Index | Thread Index | Old Index