* gcc.dg/stack-check-5.c: Skip with -fstack-protector.
[official-gcc.git] / gcc / testsuite / gcc.dg / switch-warn-1.c
blob58fbd7d4860e2e37bb913f2c5aed6d1a4bf282bb
1 /* { dg-do run } */
2 /* { dg-options "-O0" } */
4 extern void abort (void);
5 extern void exit (int);
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)
12 switch (i)
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;
23 /* Like above, but for case ranges that need to be satured. */
24 int
25 foo2 (unsigned char i)
27 switch (i)
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;
38 int
39 main (void)
41 if (foo1 (10) != 3)
42 abort ();
43 if (foo2 (10) != 3)
44 abort ();
45 exit (0);