| 1 |
/* Test for a bogus warning on comparison between signed and unsigned. |
| 2 |
Origin: Kaveh R. Ghazi <[email protected]> 5/13/2001. */ |
| 3 |
|
| 4 |
/* { dg-do compile } */ |
| 5 |
/* { dg-options "-fshow-column -Wsign-compare -fstrict-overflow" } */ |
| 6 |
|
| 7 |
extern void bar(void); |
| 8 |
|
| 9 |
int foo(int x, int y, unsigned u) |
| 10 |
{ |
| 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 "9:different signedness" "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; |
| 23 |
|
| 24 |
/* Test an ABS_EXPR, which is by definition non-negative when |
| 25 |
-fstrict-overflow is used. */ |
| 26 |
if (u < __builtin_abs(x)) |
| 27 |
return x; |
| 28 |
if (__builtin_abs(x) < u) |
| 29 |
return x; |
| 30 |
if (u < (x ? __builtin_abs(x) : 10)) |
| 31 |
return x; |
| 32 |
if ((x ? 10: __builtin_abs(x)) < u) |
| 33 |
return x; |
| 34 |
|
| 35 |
/* A MODIFY_EXPR is non-negative if the new value is known to be |
| 36 |
non-negative. */ |
| 37 |
if (u < (x = -1)) /* { dg-warning "9:different signedness" "MODIFY_EXPR" } */ |
| 38 |
return x; |
| 39 |
if (u < (x = 10)) |
| 40 |
return x; |
| 41 |
if ((x = 10) < u) |
| 42 |
return x; |
| 43 |
if (u < (x = (y ? (x==y) : 10))) |
| 44 |
return x; |
| 45 |
if ((x = (y ? 10 : (x==y))) < u) |
| 46 |
return x; |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |