2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / if-oppr.c
blob9c4910f6a20759d132fe3217962a68113860576f
1 /* Copyright (C) 2000 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 /* , not higher than ?. This is not a syntax error if it is. */
23 #if 1 ? 0, 1: 1 /* { dg-error "without" "? higher precedence than ," } */
24 #error
25 #endif
27 /* : strictly higher than ?. This would give a syntax error otherwise. */
28 #if 0 ? 0 : 1 ? 1 : 1
29 #endif
31 /* || strictly higher than ?:. */
32 #if 1 ? 0: 0 || 1
33 #error operator ?: has higher precedence than operator ||
34 #endif
36 /* && strictly higher than ||. */
37 #if 1 || 0 && 0
38 #else
39 #error operator || has higher precedence than operator &&
40 #endif
42 /* | strictly higher than &&. */
43 #if 0 && 0 | 1
44 #error operator && has higher precedence than operator |
45 #endif
47 /* ^ strictly higher than |. */
48 #if 1 | 0 ^ 1
49 #else
50 #error operator | has higher precedence than operator ^
51 #endif
53 /* & strictly higher than ^. */
54 #if 1 ^ 0 & 0
55 #else
56 #error operator ^ has higher precedence than operator &
57 #endif
59 /* == (!=) strictly higher than &. */
60 #if 0 & 0 == 0
61 #error operator & has higher precedence than operator ==
62 #endif
64 /* < (>, <=, >=) strictly higher than == (!=). */
66 #if 0 == 0 < 0
67 #else
68 #error operator == has higher precedence than operator <
69 #endif
71 /* << (>>) strictly higher than < (>, <=, >=). */
72 #if 1 < 1 << 1
73 #else
74 #error operator < has higher precedence than operator <<
75 #endif
77 /* Binary + (-) strictly higher than << (>>). */
78 #if 0 << 0 + 1
79 #error operator << has higher precedence than binary +
80 #endif
82 /* Binary * (/, %) strictly higher than binary + (-). */
83 #if 1 + 0 * 0
84 #else
85 #error binary + has higher precedence than binary *
86 #endif
88 /* Unary operators (!, ~, -, +) strictly higher than binary * (/, %).
89 Equality is hard to detect because of right-associativity. */
90 #if ~1 * 0
91 #error binary * has higher precedence than operator ~
92 #endif
94 /* () > Unary. Unfortunately this requires an additional operator. */
95 #if -(1 - 1)
96 #error unary - has higher precedence than operator ()
97 #endif