struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / caseranges.c
blob401a52c15faaa6d2e37a13efab83202596f42093
1 /** Test case for case range expressions
2 */
4 #include <testfwk.h>
6 #ifdef __SDCC
7 _Pragma("save")
8 // case range expressions are a C2y feature
9 _Pragma("std_c2y")
10 // we know that some of the case ranges are empty
11 _Pragma("disable_warning 300")
12 #endif
14 // case range expressions were originally a GNU extension => test GNU-like host compilers, too
15 #if defined(__SDCC) || defined(__GNUC__)
16 void
17 testCaseRanges (void)
19 for (int n = 0; n <= 11; n++)
21 // switch statement adapted from n3370
22 switch (n)
24 case 1:
25 ASSERT (n == 1);
26 break;
27 // case 4 : // error, overlaps 2 ... 5
28 // foo ();
29 // break;
30 case 2 ... 5:
31 ASSERT (n >= 2 && n <= 5);
32 break;
33 case 6 ... 6: // OK (but questionable)
34 ASSERT (n == 6);
35 break;
36 case 8 ... 7: // not a GCC error
37 ASSERT (0);
38 break;
39 case 10 ... 4: // not a GCC error despite overlap
40 ASSERT (0);
41 break;
42 default:
43 ASSERT (n < 1 || n > 6);
44 break;
48 #endif
50 #ifdef __SDCC
51 _Pragma("restore")
52 #endif