[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / warn-strict-prototypes.c
blob21e6f8ed7868a73910754132b9d80d30db80cc7f
1 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -Wno-error=implicit-int -verify %s
2 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -Wno-error=implicit-int -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
4 // function definition with 0 params, no prototype, no preceding declaration.
5 void foo0() {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
7 // function declaration with unspecified params
8 void foo1(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
9 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void"
10 // function declaration with 0 params
11 void foo2(void);
13 // function definition with 0 params, no prototype.
14 void foo1() {} // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
15 // function definition with 0 params, prototype.
16 void foo2(void) {}
18 // function type typedef unspecified params
19 typedef void foo3(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
20 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
22 // global fp unspecified params
23 void (*foo4)(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
24 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void"
26 // struct member fp unspecified params
27 struct { void (*foo5)(); } s; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void"
30 // param fp unspecified params
31 void bar2(void (*foo6)()) { // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
32 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void"
33 // local fp unspecified params
34 void (*foo7)() = 0; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
35 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void"
36 // array fp unspecified params
37 void (*foo8[2])() = {0}; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
38 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
41 // function type cast using using an anonymous function declaration
42 void bar3(void) {
43 // casting function w/out prototype to unspecified params function type
44 (void)(void(*)()) foo1; // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
45 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void"
46 // .. specified params
47 (void)(void(*)(void)) foo1;
50 // K&R function definition not preceded by full prototype
51 int foo9(a, b) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
52 int a, b;
54 return a + b;
57 // Function declaration with no types
58 void foo10(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} \
59 expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition}}
60 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"void"
61 // K&R function definition with incomplete param list declared
62 void foo10(p, p2) void *p; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}} \
63 expected-warning {{parameter 'p2' was not declared, defaults to 'int'; ISO C99 and later do not support implicit int}}
65 void foo11(int p, int p2);
66 void foo11(p, p2) int p; int p2; {} // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
68 // PR31020
69 void __attribute__((cdecl)) foo12(d) // expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C2x}}
70 short d;
73 // No warnings for variadic functions. Overloadable attribute is required
74 // to avoid err_ellipsis_first_param error.
75 // rdar://problem/33251668
76 void foo13(...) __attribute__((overloadable));
77 void foo13(...) __attribute__((overloadable)) {}
79 // We should not generate a strict-prototype warning for an implicit
80 // declaration. Leave that up to the implicit-function-declaration warning.
81 void foo14(void) {
82 foo14_call(); // no-warning
85 // Ensure that redeclarations involving a typedef type work properly, even if
86 // there are function attributes involved in the declaration.
87 typedef void foo_t(unsigned val);
88 __attribute__((noreturn)) foo_t foo15;
89 foo_t foo15; // OK
90 void foo15(unsigned val); // OK
92 foo_t foo16;
93 void foo16(unsigned val); // OK