| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O0" } */ |
| 3 |
|
| 4 |
extern void abort (void); |
| 5 |
extern void exit (int); |
| 6 |
|
| 7 |
/* Check that out-of-bounds case warnings work in the case that the |
| 8 |
testing expression is promoted. */ |
| 9 |
int |
| 10 |
foo1 (unsigned char i) |
| 11 |
{ |
| 12 |
switch (i) |
| 13 |
{ |
| 14 |
case -1: /* { dg-warning "case label value is less than minimum value for type|statement will never be executed" } */ |
| 15 |
return 1; |
| 16 |
case 256: /* { dg-warning "case label value exceeds maximum value for type" } */ |
| 17 |
return 2; |
| 18 |
default: |
| 19 |
return 3; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
/* Like above, but for case ranges that need to be satured. */ |
| 24 |
int |
| 25 |
foo2 (unsigned char i) |
| 26 |
{ |
| 27 |
switch (i) |
| 28 |
{ |
| 29 |
case -1 ... 1: /* { dg-warning "lower value in case label range less than minimum value for type" } */ |
| 30 |
return 1; |
| 31 |
case 254 ... 256: /* { dg-warning "upper value in case label range exceeds maximum value for type" } */ |
| 32 |
return 2; |
| 33 |
default: |
| 34 |
return 3; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
int |
| 39 |
main (void) |
| 40 |
{ |
| 41 |
if (foo1 (10) != 3) |
| 42 |
abort (); |
| 43 |
if (foo2 (10) != 3) |
| 44 |
abort (); |
| 45 |
exit (0); |
| 46 |
} |
| 47 |
|