OSDN Git Service

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