implemented thiscall by copying logic from fastcall
[tinycc.git] / tests / tests2 / 60_errors_and_warnings.c
blob47da0487aead6aebe11c48ee5005e73582fdf3cd
1 #if defined test_56_btype_excess_1
2 struct A {} int i;
4 #elif defined test_57_btype_excess_2
5 char int i;
7 #elif defined test_58_function_redefinition
8 int f(void) { return 0; }
9 int f(void) { return 1; }
11 #elif defined test_global_redefinition
12 int xxx = 1;
13 int xxx;
14 int xxx = 2;
16 #elif defined test_59_function_array
17 int (*fct)[42](int x);
19 #elif defined test_60_enum_redefinition
20 enum color { RED, GREEN, BLUE };
21 enum color { R, G, B };
22 enum color c;
24 #elif defined test_62_enumerator_redefinition
25 enum color { RED, GREEN, BLUE };
26 enum rgb { RED, G, B};
27 enum color c = RED;
29 #elif defined test_63_local_enumerator_redefinition
30 enum {
31 FOO,
32 BAR
35 int main(void)
37 enum {
38 FOO = 2,
39 BAR
42 return BAR - FOO;
45 #elif defined test_61_undefined_enum
46 enum rgb3 c = 42;
48 #elif defined test_74_non_const_init
49 int i = i++;
51 #elif defined test_pointer_assignment
53 void (*f1)(void);
54 void f2(void) {}
56 struct s1 *ps1;
57 struct s2 *ps2;
59 void *v1, **v2, ***v3;
61 enum e1 { a = 4 } e10, *e11, *e12;
62 enum e2 { b = -4 } e20, *e21;
63 enum e3 { c = 5000000000LL } e30;
65 int *ip;
66 unsigned int *up;
67 long *lp;
68 long long *llp;
70 char **c1;
71 char const **c2;
72 unsigned char **u1;
74 int no_main ()
76 // function
77 f1 = f2;
78 // struct
79 ps1 = ps2;
80 // void*
81 v1 = v3;
82 v2 = v3;
84 // enum
85 e11 = e12;
86 e11 = e21;
87 e11 = &e10;
88 ip = &e10;
89 ip = &e20;
90 up = &e10;
91 up = &e20;
92 up = &e30;
94 lp = ip;
95 lp = llp;
97 // constness
98 c1 = c2;
99 *c1 = *c2;
100 **c1 = **c2;
102 // unsigned = signed
103 u1 = c2;
104 *u1 = *c2;
105 **u1 = **c2;
107 c2 = c1;
108 *c2 = *c1;
109 **c2 = **c1;
111 return 0;
115 #elif defined test_enum_compat
116 enum e4;
117 enum e5;
118 void f3(enum e4 e);
119 void f3(enum e5 e);
121 #elif defined test_enum_compat_2
122 enum e6 { E1 = -1, E0 };
123 void f3(enum e6);
124 void f3(int); // should work as int and e6 are compatible
125 void f4(enum e6 e);
126 void f4(unsigned e); // should error as unsigned and e6 are incompatible
128 #elif defined test_ptr_to_str
129 void f() { _Generic((int const *[]){0}, int:0); }
130 #elif defined test_fnptr_to_str
131 void f() { _Generic((int (*(*)(float,char))(double,int)){0}, int:0); }
132 #elif defined test_array_to_str
133 void f() { _Generic((int(*)[3]){0}, int:0); }
134 #elif defined test_duplicate_def_1
135 static enum myenum { L = -1 } L;
136 #elif defined test_duplicate_def_2
137 void foo(void) {
138 static enum myenum { L = -1 } L;
140 #elif defined test_abstract_decls
141 int bar(const char *()); // abstract declarator here is okay
142 int bar (const char *(*g)()) // should match this 'g' argument
144 g();
145 return 42;
147 int foo(int ()) // abstract decl is wrong in definitions
149 return 0;
150 #elif defined test_invalid_1
151 void f(char*);
152 void g(void) {
153 f((char[]){1, ,});
155 #elif defined test_invalid_2
156 int ga = 0.42 { 2 };
157 #elif defined test_invalid_3
158 struct S { int a, b; };
159 struct T { struct S x; };
160 struct T gt = { 42 a: 1, 43 };
161 #elif defined test_invalid_4
162 enum E {
163 x = 1 / 0
165 #elif defined test_conflicting_types
166 int i;
167 void foo(void) {
168 int i;
170 extern double i;
171 i = 42.2;
174 #elif defined test_nested_types
175 union u {
176 union u {
177 int i;
178 } m;
180 #elif defined test_vla_1
181 int X=1;
183 int main(void) {
184 int t[][][X];
186 #elif defined test_invalid_alignas
187 /* _Alignas is no type qualifier */
188 void * _Alignas(16) p1;
190 #elif defined test_static_assert
192 #define ONE 0
193 _Static_assert(ONE == 0, "don't show me this");
194 struct x{ _Static_assert(ONE == 1, "ONE is not 1"); };
196 #elif defined test_static_assert_2
197 _Static_assert(1, "1"" is 1");
198 struct y { _Static_assert(0, "0"" is 0"); };
200 #elif defined test_static_assert_c2x
201 _Static_assert(1);
202 struct z { _Static_assert(0); }
204 #elif defined test_static_assert_empty_string
205 _Static_assert(0,"");
207 #elif defined test_void_array
208 void t[3];
210 #elif defined test_incomplete_enum_array
211 enum e t[3];
213 #elif defined test_incomplete_struct_array
214 struct s t[3];
216 #elif defined test_const_fun_array
217 typedef void f(void);
218 const f t[3];
220 #elif defined test_incomplete_array_array
221 int t[][3]; // gr: not an error, see below
223 /******************************************************************/
224 #elif defined test_extern_array
225 int iii[] = { 1,2,3 };
226 extern int iii[];
227 int x[];
228 int x[2];
229 int x[];
230 int x[2];
231 int x[];
232 extern int x[2];
233 extern int x[];
234 int x[3];
236 /******************************************************************/
237 #elif defined test_func_1 \
238 || defined test_func_2 \
239 || defined test_func_3 \
240 || defined test_func_4 \
241 || defined test_func_5 \
242 || defined test_func_6
243 #if defined test_func_1
244 int hello(int);
245 #elif defined test_func_4
246 static int hello(int);
247 #endif
248 int main () {
249 #if defined test_func_6
250 static
251 #endif
252 int hello(int);
253 hello(123);
254 return 0;
256 int printf(const char*, ...);
257 #if defined test_func_3
258 static int hello(int a)
259 #elif defined test_func_5
260 int hello(int a, int b)
261 #else
262 int hello(int a)
263 #endif
264 { printf("%s: a = %d\n", __FUNCTION__, a); return 0; }
266 /******************************************************************/
267 #elif defined test_var_1 \
268 || defined test_var_2 \
269 || defined test_var_3
270 #define P(n,v) printf("%-5s: %d ; %d\n", __FUNCTION__, n, v)
271 #if defined test_var_1
272 int xxx[];
273 #endif
274 int bar();
275 int printf(const char*, ...);
276 int main ()
278 #if !defined test_var_3
279 int xxx = 2;
280 #endif
282 extern int xxx[
283 #if defined test_var_3
285 #endif
287 P(1, xxx[0]);
288 xxx[0] += 2;
290 #if !defined test_var_3
291 P(2, xxx);
292 #endif
293 bar(123);
294 return 0;
296 int xxx[1] = {1};
297 int bar() { P(3, xxx[0]); return 0; }
299 #elif defined test_var_4
300 struct yyy { int y; };
301 struct zzz;
302 void f1() {
303 extern char *x;
304 extern char **xx;
305 extern struct yyy y;
306 extern struct yyy *yy;
307 extern struct zzz z;
308 extern struct zzz *zz;
310 void f2() {
311 extern char *x;
312 extern char **xx;
313 extern struct yyy y;
314 extern struct yyy *yy;
315 extern struct zzz z;
316 extern struct zzz *zz;
318 struct yyy y, *yy;
319 struct zzz { int z; } z, *zz;
321 /******************************************************************/
322 #elif defined test_long_double_type_for_win32
324 int main()
326 double *a = 0;
327 long double *b = a;
328 int n = _Generic(*a, double:0, long double:1);
331 #elif defined test_stray_backslash
332 #define x \a
335 #elif defined test_stray_backslash2
336 int printf(const char*, ...);
337 int main()
339 #define _S(x) #x
340 #define S(x) _S(x)
341 printf("%sn\n", S(\\));
344 /******************************************************************/
345 #elif defined test_var_array
347 static struct var_len { int i; const char str[]; } var_array[] =
348 { { 1, "abcdefghijklmnopqrstuvwxyz" },
349 { 2, "longlonglonglonglong" },
350 { 3, "tst3" } };
352 #elif defined test_var_array2
354 struct c1 { int a; int b[]; };
355 struct c1 c1 = { 1, { 2, 3, 4 } };
357 struct c2 { int c; struct c1 c1; };
358 struct c2 c2 = { 1, { 2, { 3, 4, 5 }}};
360 #elif defined test_var_array3
361 /* similar to test_var_array2 but with string initializers */
362 struct A { int a; char b[]; };
363 struct A a = { 1, "1" };
364 struct B { struct A a; };
365 struct B b = { { 1, "1" } };
366 /******************************************************************/
367 #elif defined test_default_int_type
368 n; // warn
369 f(); // don't warn
371 #elif defined test_invalid_global_stmtexpr
372 n[sizeof({3;})]; // crashed in block() due to missing local scope
374 #elif defined test_invalid_tokckill
375 f(){"12"3;} // second const token killed the value of the first
377 /******************************************************************/
378 #elif defined test_duplicate_member
379 struct S {
380 int a, a;
382 #elif defined test_duplicate_member_anon
383 struct S1 {
384 int b;
385 struct {
386 int b;
387 } c;
389 struct S2 {
390 int d;
391 struct {
392 int d;
396 /******************************************************************/
397 #elif defined test_conflicting_array_definition
398 extern int array[2];
399 int array[] = { 1, 2, 3 };
401 #elif defined test_incompatible_local_redef
402 void foo (void)
404 typedef int localfunctype (int);
405 extern localfunctype func2;
406 typedef void localfunctype (int, int);
409 #elif defined test_cast_from_void
410 void v() {}
411 int f() { return v(); }
413 #elif defined test_switch_W1 || defined test_switch_W2 \
414 || defined test_switch_W3 || defined test_switch_W4
415 #if defined test_switch_W1
416 #pragma comment(option, "-Wall")
417 #elif defined test_switch_W2
418 #pragma comment(option, "-Wunsupported -Wno-implicit-function-declaration -Wstuff")
419 #elif defined test_switch_W3
420 #pragma comment(option, "-Wwrite-strings -Werror=discarded-qualifiers")
421 #elif defined test_switch_W4
422 #pragma comment(option, "-Wunsupported -Wno-error=implicit-function-declaration -Werror")
423 #endif
424 void func()
426 char *ccp = "123";
427 fink();
429 __attribute__((stuff)) int fink() {return 0;}
431 #elif defined test_invalid_funcparam_1
432 void func(int a, int b, int a);
434 #elif defined test_invalid_funcparam_2
435 void func(int a, int if);
437 #elif defined test_array_funcparam
438 int amain(int argc, char *argv[static argc + 1])
440 int i;
441 int printf(const char*, ...);
442 for (i = 0; i < argc; ++i)
443 printf("arg[%d] = \"%s\"\n", i, argv[i]);
444 return 0;
446 int main()
448 return amain(2, (char *[]){ "X", "Y", 0 });
451 #elif defined test_return_from_statement_expr
452 int f() { ({ return 78; }); }
453 int main() { return f(); }
455 /******************************************************************/
457 #elif defined test_illegal_unicode
458 int main() {
459 char *str = "\Uffffffff";
462 #elif defined test_error_string
463 #error \123\\
466 #elif defined test_error_incomplete_type
467 struct A;
468 void f(struct A *);
470 int main()
472 f(&(struct A){});
475 struct A {
476 int x;
479 #elif defined test_pp_error_1
480 # if //no expression
481 # endif
482 #elif defined test_pp_error_2
483 # if X(1,2) //undefined function macro
484 # endif
486 #endif