| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Wtype-limits" } */ |
| 3 |
|
| 4 |
extern void assert (int); |
| 5 |
|
| 6 |
void a (unsigned char x) |
| 7 |
{ |
| 8 |
if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ |
| 9 |
if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ |
| 10 |
if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ |
| 11 |
if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ |
| 12 |
if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */ |
| 13 |
return; |
| 14 |
if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */ |
| 15 |
return; |
| 16 |
if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } } */ |
| 17 |
return; |
| 18 |
if (255 >= (unsigned char) 1) |
| 19 |
return; |
| 20 |
|
| 21 |
} |
| 22 |
|
| 23 |
void b (unsigned short x) |
| 24 |
{ |
| 25 |
if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" "" { target { ! short_eq_int } } } */ |
| 26 |
/* { dg-warning "comparison of unsigned expression in '< 0' is always false" "" { target short_eq_int } .-1 } */ |
| 27 |
if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" "" { target { ! short_eq_int } } } */ |
| 28 |
/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" "" { target short_eq_int } .-1 } */ |
| 29 |
if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" "" { target { ! short_eq_int } } } */ |
| 30 |
/* { dg-warning "comparison of unsigned expression in '< 0' is always false" "" { target short_eq_int } .-1 } */ |
| 31 |
if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" "" { target { ! short_eq_int } } } */ |
| 32 |
/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" "" { target short_eq_int } .-1 } */ |
| 33 |
} |
| 34 |
|
| 35 |
void c (unsigned int x) |
| 36 |
{ |
| 37 |
if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 38 |
if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 39 |
if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 40 |
if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 41 |
if (1U >= 0) return; |
| 42 |
if (1U < 0) return; |
| 43 |
if (0 <= 1U) return; |
| 44 |
if (0 > 1U) return; |
| 45 |
} |
| 46 |
|
| 47 |
void d (unsigned long x) |
| 48 |
{ |
| 49 |
if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 50 |
if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 51 |
if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 52 |
if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 53 |
} |
| 54 |
|
| 55 |
void e (unsigned long long x) |
| 56 |
{ |
| 57 |
if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 58 |
if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 59 |
if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
| 60 |
if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ |
| 61 |
} |
| 62 |
|
| 63 |
int test (int x) |
| 64 |
{ |
| 65 |
if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } } */ |
| 66 |
return 1; |
| 67 |
else |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
template <typename Int, Int D> |
| 72 |
void f(Int x) { |
| 73 |
assert(0 <= x and x <= D); |
| 74 |
} |
| 75 |
|
| 76 |
void ff(void) { |
| 77 |
f<unsigned char, 2>(5); |
| 78 |
f<signed char, 2>(5); |
| 79 |
} |
| 80 |
|
| 81 |
template <typename Int, Int D> |
| 82 |
void g(void) { |
| 83 |
assert(0 <= D); |
| 84 |
} |
| 85 |
void gg(void) { |
| 86 |
g<unsigned char, 2>(); |
| 87 |
} |
| 88 |
|