]>
Commit | Line | Data |
---|---|---|
f6aa72dd MLI |
1 | /* Test that -Wtype-limits is enabled by -Wextra */ |
2 | /* { dg-do compile } */ | |
77cacee4 | 3 | /* { dg-excess-errors "short=int" { target { avr-*-* } } } */ |
f6aa72dd MLI |
4 | /* { dg-options "-Wextra" } */ |
5 | ||
f6aa72dd MLI |
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; | |
c3125b18 | 16 | if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } } */ |
f6aa72dd MLI |
17 | return; |
18 | if (255 >= (unsigned char) 1) | |
19 | return; | |
20 | ||
21 | } | |
22 | ||
23 | void b (unsigned short x) | |
a9c697b8 | 24 | { /* { dg-warning "comparison of unsigned expression '< 0' is always false" "" { target { ! int32plus } } .+1 } */ |
5b21d7b2 | 25 | if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" "" { target { int32plus } } } */ |
a9c697b8 | 26 | /* { dg-warning "comparison of unsigned expression '>= 0' is always true" "" { target { ! int32plus } } .+1 } */ |
5b21d7b2 | 27 | if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" "" { target { int32plus } } } */ |
a9c697b8 | 28 | /* { dg-warning "comparison of unsigned expression '< 0' is always false" "" { target { ! int32plus } } .+1 } */ |
5b21d7b2 | 29 | if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" "" { target { int32plus } } } */ |
a9c697b8 | 30 | /* { dg-warning "comparison of unsigned expression '>= 0' is always true" "" { target { ! int32plus } } .+1 } */ |
5b21d7b2 | 31 | if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" "" { target { int32plus } } } */ |
f6aa72dd MLI |
32 | } |
33 | ||
34 | void c (unsigned int x) | |
35 | { | |
a9c697b8 MS |
36 | if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
37 | if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
38 | if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ | |
39 | if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
f6aa72dd MLI |
40 | if (1U >= 0) return; |
41 | if (1U < 0) return; | |
42 | if (0 <= 1U) return; | |
43 | if (0 > 1U) return; | |
44 | } | |
45 | ||
46 | void d (unsigned long x) | |
47 | { | |
a9c697b8 MS |
48 | if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
49 | if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
50 | if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ | |
51 | if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
f6aa72dd MLI |
52 | } |
53 | ||
54 | void e (unsigned long long x) | |
55 | { | |
a9c697b8 MS |
56 | if (x < 0) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ |
57 | if (x >= 0) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
58 | if (0 > x) return;/* { dg-warning "comparison of unsigned expression in '< 0' is always false" } */ | |
59 | if (0 <= x) return;/* { dg-warning "comparison of unsigned expression in '>= 0' is always true" } */ | |
f6aa72dd MLI |
60 | } |
61 | ||
62 | int test (int x) | |
63 | { | |
c3125b18 | 64 | if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } } */ |
f6aa72dd MLI |
65 | return 1; |
66 | else | |
67 | return 0; | |
68 | } | |
69 | ||
77cacee4 | 70 |