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. */
14 #error #else block evaluated for true conditional
18 #error #if block evaluated for false conditional
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 ," } */
27 /* : strictly higher than ?. This would give a syntax error otherwise. */
31 /* || strictly higher than ?:. */
33 #error operator ?: has higher precedence than operator ||
36 /* && strictly higher than ||. */
39 #error operator || has higher precedence than operator &&
42 /* | strictly higher than &&. */
44 #error operator && has higher precedence than operator |
47 /* ^ strictly higher than |. */
50 #error operator | has higher precedence than operator ^
53 /* & strictly higher than ^. */
56 #error operator ^ has higher precedence than operator &
59 /* == (!=) strictly higher than &. */
61 #error operator & has higher precedence than operator ==
64 /* < (>, <=, >=) strictly higher than == (!=). */
68 #error operator == has higher precedence than operator <
71 /* << (>>) strictly higher than < (>, <=, >=). */
74 #error operator < has higher precedence than operator <<
77 /* Binary + (-) strictly higher than << (>>). */
79 #error operator << has higher precedence than binary +
82 /* Binary * (/, %) strictly higher than binary + (-). */
85 #error binary + has higher precedence than binary *
88 /* Unary operators (!, ~, -, +) strictly higher than binary * (/, %).
89 Equality is hard to detect because of right-associativity. */
91 #error binary * has higher precedence than operator ~
94 /* () > Unary. Unfortunately this requires an additional operator. */
96 #error unary - has higher precedence than operator ()