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> */
5 /* { dg-do compile } */
6 /* { dg-options "-Wparentheses" } */
11 bar (int a
, int b
, int c
)
13 foo (a
<= b
<= c
); /* { dg-warning "mathematical meaning" "correct warning" } */
16 foo (1 <= 2 <= c
); /* { dg-warning "mathematical meaning" "correct warning" } */
19 foo (1 <= 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */
22 foo (a
> b
> c
); /* { dg-warning "mathematical meaning" "correct warning" } */
25 foo (1 > 2 > c
); /* { dg-warning "mathematical meaning" "correct warning" } */
28 foo (1 > 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */
31 foo (a
< b
<= c
); /* { dg-warning "mathematical meaning" "correct warning" } */
34 foo (1 < 2 <= c
); /* { dg-warning "mathematical meaning" "correct warning" } */
37 foo (1 < 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */
40 foo (a
<= b
> c
); /* { dg-warning "mathematical meaning" "correct warning" } */
43 foo (1 <= 2 > c
); /* { dg-warning "mathematical meaning" "correct warning" } */
46 foo (1 <= 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */
49 foo (a
<= b
== c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
52 foo (1 <= 2 == c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
55 foo (1 <= 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
58 foo (a
!= b
!= c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
61 foo (1 != 2 != c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
64 foo (1 != 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
67 foo (a
< b
== c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
70 foo (a
> b
== c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
73 foo (a
== b
< c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
76 foo (a
== b
> c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
79 foo (a
== b
== c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
82 foo (1 == 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
85 foo (1 < 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
88 foo (1 > 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
91 foo (1 == 2 < 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
94 foo (1 == 2 > 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
97 foo (a
< b
!= c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
100 foo (a
> b
!= c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
103 foo (a
!= b
< c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
106 foo (a
!= b
> c
); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
109 foo (1 < 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
112 foo (1 > 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
115 foo (1 != 2 < 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */
118 foo (1 != 2 > 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */