Merge from mainline.
[official-gcc.git] / gcc / testsuite / gcc.dg / compare4.c
blob5f567c5df79d54539fc4c9417b635ef188e39ea3
1 /* Test for a bogus warning on comparison between signed and unsigned.
2 Origin: Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 5/13/2001. */
4 /* { dg-do compile } */
5 /* { dg-options "-Wsign-compare" } */
7 extern void bar(void);
9 int foo(int x, int y, unsigned u)
11 /* A COMPOUND_EXPR is non-negative if the last element is known to
12 be non-negative. */
13 if (u < (bar(), -1)) /*{ dg-warning "signed and unsigned" "COMPOUND_EXPR" }*/
14 return x;
15 if (u < (bar(), 10))
16 return x;
17 if ((bar(), 10) < u)
18 return x;
19 if (u < (x ? (bar(),bar(),bar(),bar(),x==y) : 10))
20 return x;
21 if ((x ? 10 : (bar(),bar(),bar(),bar(),x==y)) < u)
22 return x;
24 /* Test an ABS_EXPR, which is by definition non-negative. */
25 if (u < __builtin_abs(x))
26 return x;
27 if (__builtin_abs(x) < u)
28 return x;
29 if (u < (x ? __builtin_abs(x) : 10))
30 return x;
31 if ((x ? 10: __builtin_abs(x)) < u)
32 return x;
34 /* A MODIFY_EXPR is non-negative if the new value is known to be
35 non-negative. */
36 if (u < (x = -1)) /* { dg-warning "signed and unsigned" "MODIFY_EXPR" } */
37 return x;
38 if (u < (x = 10))
39 return x;
40 if ((x = 10) < u)
41 return x;
42 if (u < (x = (y ? (x==y) : 10)))
43 return x;
44 if ((x = (y ? 10 : (x==y))) < u)
45 return x;
47 return 0;