summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cpp/if-oppr.c
blob: a46a815cf99d9f2d362e416c802f31b3c9fdc7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright (C) 2000, 2008 Free Software Foundation, Inc.  */

/* Test the full range of preprocessor operator precedence.  Each
   operator is tested with one of immediately higher precedence to
   verify it is of strictly lower precedence.  To avoid complications,
   each test uses just those two operators.  Occasionally this assumes
   correct operation of if-then-else, so the first tests verify this.  */

/* { dg-do preprocess } */

/* Ensure correct functioning of if-then-else.  */
#if 1
#else
#error #else block evaluated for true conditional
#endif

#if 0
#error #if block evaluated for false conditional
#else
#endif

/* : strictly higher than ?.  This would give a syntax error otherwise.  */
#if 0 ? 0 : 1 ? 1 : 1
#endif

/* || strictly higher than ?:. */
#if 1 ? 0: 0 || 1
#error operator ?: has higher precedence than operator ||
#endif

/* && strictly higher than ||.  */
#if 1 || 0 && 0
#else
#error operator || has higher precedence than operator &&
#endif

/* | strictly higher than &&.  */
#if 0 && 0 | 1
#error operator && has higher precedence than operator |
#endif

/* ^ strictly higher than |.  */
#if 1 | 0 ^ 1
#else
#error operator | has higher precedence than operator ^
#endif

/* & strictly higher than ^.  */
#if 1 ^ 0 & 0
#else
#error operator ^ has higher precedence than operator &
#endif

/* == (!=) strictly higher than &.  */
#if 0 & 0 == 0
#error operator & has higher precedence than operator ==
#endif

/* < (>, <=, >=) strictly higher than == (!=).  */

#if 0 == 0 < 0
#else
#error operator == has higher precedence than operator <
#endif

/* << (>>) strictly higher than < (>, <=, >=).  */
#if 1 < 1 << 1
#else
#error operator < has higher precedence than operator <<
#endif

/* Binary + (-) strictly higher than << (>>).  */
#if 0 << 0 + 1
#error operator << has higher precedence than binary +
#endif

/* Binary * (/, %) strictly higher than binary + (-).  */
#if 1 + 0 * 0
#else
#error binary + has higher precedence than binary *
#endif

/* Unary operators (!, ~, -, +) strictly higher than binary * (/, %).
   Equality is hard to detect because of right-associativity.  */
#if ~1 * 0
#error binary * has higher precedence than operator ~
#endif

/* () > Unary.  Unfortunately this requires an additional operator.  */
#if -(1 - 1)
#error unary - has higher precedence than operator ()
#endif