1 /* Test operation of -Wparentheses.  Warnings for X<=Y<=Z should be
2    there rather than hidden in -Wextra.  */
3 /* Origin: Joseph Myers <jsm@polyomino.org.uk> */
4 
5 /* { dg-do compile } */
6 /* { dg-options "-Wparentheses" } */
7 
8 int foo (int);
9 
10 int
bar(int a,int b,int c)11 bar (int a, int b, int c)
12 {
13   foo (a <= b <= c); /* { dg-warning "mathematical meaning" "correct warning" } */
14   foo ((a <= b) <= c);
15   foo (a <= (b <= c));
16   foo (1 <= 2 <= c); /* { dg-warning "mathematical meaning" "correct warning" } */
17   foo ((1 <= 2) <= c);
18   foo (1 <= (2 <= c));
19   foo (1 <= 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */
20   foo ((1 <= 2) <= 3);
21   foo (1 <= (2 <= 3));
22   foo (a > b > c); /* { dg-warning "mathematical meaning" "correct warning" } */
23   foo ((a > b) > c);
24   foo (a > (b > c));
25   foo (1 > 2 > c); /* { dg-warning "mathematical meaning" "correct warning" } */
26   foo ((1 > 2) > c);
27   foo (1 > (2 > c));
28   foo (1 > 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */
29   foo ((1 > 2) > 3);
30   foo (1 > (2 > 3));
31   foo (a < b <= c); /* { dg-warning "mathematical meaning" "correct warning" } */
32   foo ((a < b) <= c);
33   foo (a < (b <= c));
34   foo (1 < 2 <= c); /* { dg-warning "mathematical meaning" "correct warning" } */
35   foo ((1 < 2) <= c);
36   foo (1 < (2 <= c));
37   foo (1 < 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */
38   foo ((1 < 2) <= 3);
39   foo (1 < (2 <= 3));
40   foo (a <= b > c); /* { dg-warning "mathematical meaning" "correct warning" } */
41   foo ((a <= b) > c);
42   foo (a <= (b > c));
43   foo (1 <= 2 > c); /* { dg-warning "mathematical meaning" "correct warning" } */
44   foo ((1 <= 2) > c);
45   foo (1 <= (2 > c));
46   foo (1 <= 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */
47   foo ((1 <= 2) > 3);
48   foo (1 <= (2 > 3));
49   foo (a <= b == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
50   foo ((a <= b) == c);
51   foo (a <= (b == c));
52   foo (1 <= 2 == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
53   foo ((1 <= 2) == c);
54   foo (1 <= (2 == c));
55   foo (1 <= 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
56   foo ((1 <= 2) == 3);
57   foo (1 <= (2 == 3));
58   foo (a != b != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
59   foo ((a != b) != c);
60   foo (a != (b != c));
61   foo (1 != 2 != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
62   foo ((1 != 2) != c);
63   foo (1 != (2 != c));
64   foo (1 != 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
65   foo ((1 != 2) != 3);
66   foo (1 != (2 != 3));
67   foo (a < b == c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
68   foo ((a < b) == c);
69   foo (a < (b == c));
70   foo (a > b == c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
71   foo ((a > b) == c);
72   foo (a > (b == c));
73   foo (a == b < c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
74   foo ((a == b) < c);
75   foo (a == (b < c));
76   foo (a == b > c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
77   foo ((a == b) > c);
78   foo (a == (b > c));
79   foo (a == b == c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
80   foo ((a == b) == c);
81   foo (a == (b == c));
82   foo (1 == 2 == 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
83   foo ((1 == 2) == 3);
84   foo (1 == (2 == 3));
85   foo (1 < 2 == 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
86   foo ((1 < 2) == 3);
87   foo (1 < (2 == 3));
88   foo (1 > 2 == 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
89   foo ((1 > 2) == 3);
90   foo (1 > (2 == 3));
91   foo (1 == 2 < 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
92   foo ((1 == 2) < 3);
93   foo (1 == (2 < 3));
94   foo (1 == 2 > 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
95   foo ((1 == 2) > 3);
96   foo (1 == (2 > 3));
97   foo (a < b != c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
98   foo ((a < b) != c);
99   foo (a < (b != c));
100   foo (a > b != c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
101   foo ((a > b) != c);
102   foo (a > (b != c));
103   foo (a != b < c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
104   foo ((a != b) < c);
105   foo (a != (b < c));
106   foo (a != b > c);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
107   foo ((a != b) > c);
108   foo (a != (b > c));
109   foo (1 < 2 != 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
110   foo ((1 < 2) != 3);
111   foo (1 < (2 != 3));
112   foo (1 > 2 != 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
113   foo ((1 > 2) != 3);
114   foo (1 > (2 != 3));
115   foo (1 != 2 < 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
116   foo ((1 != 2) < 3);
117   foo (1 != (2 < 3));
118   foo (1 != 2 > 3);  /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
119   foo ((1 != 2) > 3);
120   foo (1 != (2 > 3));
121 }
122