2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / if-oppr.c
bloba46a815cf99d9f2d362e416c802f31b3c9fdc7cb
1 /* Copyright (C) 2000, 2008 Free Software Foundation, Inc. */
3 /* Test the full range of preprocessor operator precedence. Each
4 operator is tested with one of immediately higher precedence to
5 verify it is of strictly lower precedence. To avoid complications,
6 each test uses just those two operators. Occasionally this assumes
7 correct operation of if-then-else, so the first tests verify this. */
9 /* { dg-do preprocess } */
11 /* Ensure correct functioning of if-then-else. */
12 #if 1
13 #else
14 #error #else block evaluated for true conditional
15 #endif
17 #if 0
18 #error #if block evaluated for false conditional
19 #else
20 #endif
22 /* : strictly higher than ?. This would give a syntax error otherwise. */
23 #if 0 ? 0 : 1 ? 1 : 1
24 #endif
26 /* || strictly higher than ?:. */
27 #if 1 ? 0: 0 || 1
28 #error operator ?: has higher precedence than operator ||
29 #endif
31 /* && strictly higher than ||. */
32 #if 1 || 0 && 0
33 #else
34 #error operator || has higher precedence than operator &&
35 #endif
37 /* | strictly higher than &&. */
38 #if 0 && 0 | 1
39 #error operator && has higher precedence than operator |
40 #endif
42 /* ^ strictly higher than |. */
43 #if 1 | 0 ^ 1
44 #else
45 #error operator | has higher precedence than operator ^
46 #endif
48 /* & strictly higher than ^. */
49 #if 1 ^ 0 & 0
50 #else
51 #error operator ^ has higher precedence than operator &
52 #endif
54 /* == (!=) strictly higher than &. */
55 #if 0 & 0 == 0
56 #error operator & has higher precedence than operator ==
57 #endif
59 /* < (>, <=, >=) strictly higher than == (!=). */
61 #if 0 == 0 < 0
62 #else
63 #error operator == has higher precedence than operator <
64 #endif
66 /* << (>>) strictly higher than < (>, <=, >=). */
67 #if 1 < 1 << 1
68 #else
69 #error operator < has higher precedence than operator <<
70 #endif
72 /* Binary + (-) strictly higher than << (>>). */
73 #if 0 << 0 + 1
74 #error operator << has higher precedence than binary +
75 #endif
77 /* Binary * (/, %) strictly higher than binary + (-). */
78 #if 1 + 0 * 0
79 #else
80 #error binary + has higher precedence than binary *
81 #endif
83 /* Unary operators (!, ~, -, +) strictly higher than binary * (/, %).
84 Equality is hard to detect because of right-associativity. */
85 #if ~1 * 0
86 #error binary * has higher precedence than operator ~
87 #endif
89 /* () > Unary. Unfortunately this requires an additional operator. */
90 #if -(1 - 1)
91 #error unary - has higher precedence than operator ()
92 #endif