Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / support / valdiag / tests / switch.c
blob5966440cf1470f64224e40775092f86a416c6d13
2 char x;
4 /* Valid switch statement */
5 #ifdef TEST1
6 char foo(void)
8 switch(x)
10 char y;
12 case 0:
13 return 0;
14 case 1:
15 return 1;
16 default:
17 y = x+1;
18 return y;
21 #endif
23 /* Error, duplicate cases */
24 #ifdef TEST2
25 char foo(void)
27 switch(x)
29 char y;
31 case 0: /* IGNORE */
32 return 0;
33 case 1:
34 return 1;
35 case 0: /* ERROR */
36 return 0;
37 default:
38 y = x;
39 return y;
42 #endif
44 /* Error, more than one default */
45 #ifdef TEST3
46 char foo(void)
48 switch(x)
50 char y;
52 case 0:
53 return 0;
54 case 1:
55 return 1;
56 default: /* IGNORE */
57 y = x;
58 return y;
59 default: /* ERROR */
60 return 2;
63 #endif
65 /* Warn about unreachable code */
66 #ifdef TEST4
67 char foo(void)
69 switch(x)
71 char y; /* IGNORE */
72 x++; /* WARNING(SDCC) */
74 case 0:
75 return 0;
76 case 1:
77 return 1;
78 default:
79 y = x;
80 return x;
83 #endif
85 /* Warn about unreachable initializer */
86 #ifdef TEST5
87 char foo(void)
89 switch(x)
91 char y=1; /* WARNING(SDCC) */
93 case 0:
94 return 0;
95 case 1:
96 return 1;
97 default:
98 return y; /* IGNORE */
101 #endif
103 /* Error, missing switch */
104 #ifdef TEST6
105 char foo(void)
108 case 0: /* ERROR */
109 return 0;
110 case 1: /* ERROR */
111 return 1;
112 default: /* ERROR */
113 return x;
116 #endif
118 /* Error, switch condition must be integral */
119 #ifdef TEST7
120 char foo(void)
122 float f; /* IGNORE */
123 f=x;
124 switch(f) /* ERROR */
126 char y; /* IGNORE */
128 case 0:
129 return 0;
130 case 1:
131 return 1;
132 default:
133 y = x;
134 return x;
136 return 0;
138 #endif
140 /* Error, cases must be integral */
141 #ifdef TEST8
142 char foo(void)
144 switch(x)
146 char y; /* IGNORE */
148 case 0.0: /* ERROR */
149 return 0;
150 case 1:
151 return 1;
152 default:
153 y = x;
154 return x;
157 #endif
159 #ifdef TEST9
160 _Pragma("save")
161 _Pragma("std_c23")
163 /* Error: 'case' range expressions require C2y or later */
164 char foo(void)
166 switch(x)
168 case 1 ... 3: /* ERROR */
169 return 1;
170 default:
171 return 0;
175 _Pragma("restore")
176 #endif
178 #ifdef TEST10
179 _Pragma("save")
180 _Pragma("std_c2y")
182 /* Same code as above, but valid in C2y */
183 char foo(void)
185 switch(x)
187 case 1 ... 3:
188 return 1;
189 default:
190 return 0;
194 _Pragma("restore")
195 #endif
197 #ifdef TEST11
198 _Pragma("save")
199 _Pragma("std_c2y")
201 /* Error: overlap with case range */
202 char foo(void)
204 switch(x)
206 case 1: /* IGNORE */
207 return 1;
208 case 1 ... 3: /* ERROR */
209 return 3;
210 default:
211 return 0;
215 _Pragma("restore")
216 #endif
218 #ifdef TEST12
219 _Pragma("save")
220 _Pragma("std_c2y")
222 /* Warning: 'case' range empty; case ignored */
223 char foo(void)
225 switch(x)
227 case 1:
228 return 1;
229 case 3 ... 1: /* WARNING(SDCC) */
230 return 3; /* IGNORE */ /* unreachable code warning */
231 default:
232 return 0;
236 _Pragma("restore")
237 #endif