1 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -verify %s
2 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
3
4 // function definition with 0 params, no prototype, no preceding declaration.
foo0()5 void foo0() {} // expected-warning {{this old-style function definition is not preceded by a prototype}}
6
7 // function declaration with unspecified params
8 void foo1(); // expected-warning {{this function declaration is not a prototype}}
9 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void"
10 // function declaration with 0 params
11 void foo2(void);
12
13 // function definition with 0 params, no prototype.
foo1()14 void foo1() {} // expected-warning {{this old-style function definition is not preceded by a prototype}}
15 // function definition with 0 params, prototype.
foo2(void)16 void foo2(void) {}
17
18 // function type typedef unspecified params
19 typedef void foo3(); // expected-warning {{this function declaration is not a prototype}}
20 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
21
22 // global fp unspecified params
23 void (*foo4)(); // expected-warning {{this function declaration is not a prototype}}
24 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void"
25
26 // struct member fp unspecified params
27 struct { void (*foo5)(); } s; // expected-warning {{this function declaration is not a prototype}}
28 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void"
29
30 // param fp unspecified params
bar2(void (* foo6)())31 void bar2(void (*foo6)()) { // expected-warning {{this function declaration is not a prototype}}
32 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void"
33 // local fp unspecified params
34 void (*foo7)() = 0; // expected-warning {{this function declaration is not a prototype}}
35 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void"
36 // array fp unspecified params
37 void (*foo8[2])() = {0}; // expected-warning {{this function declaration is not a prototype}}
38 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
39 }
40
41 // function type cast using using an anonymous function declaration
bar3(void)42 void bar3(void) {
43 // casting function w/out prototype to unspecified params function type
44 (void)(void(*)()) foo1; // expected-warning {{this function declaration is not a prototype}}
45 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void"
46 // .. specified params
47 (void)(void(*)(void)) foo1;
48 }
49
50 // K&R function definition not preceded by full prototype
foo9(a,b)51 int foo9(a, b) // expected-warning {{old-style function definition is not preceded by a prototype}}
52 int a, b;
53 {
54 return a + b;
55 }
56
57 // Function declaration with no types
58 void foo10(); // expected-warning {{this function declaration is not a prototype}}
59 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:12}:"void"
60 // K&R function definition with incomplete param list declared
foo10(p,p2)61 void foo10(p, p2) void *p; {} // expected-warning {{old-style function definition is not preceded by a prototype}}
62
63 // K&R function definition with previous prototype declared is not diagnosed.
64 void foo11(int p, int p2);
foo11(p,p2)65 void foo11(p, p2) int p; int p2; {}
66
67 // PR31020
foo12(d)68 void __attribute__((cdecl)) foo12(d) // expected-warning {{this old-style function definition is not preceded by a prototype}}
69 short d;
70 {}
71
72 // No warnings for variadic functions. Overloadable attribute is required
73 // to avoid err_ellipsis_first_param error.
74 // rdar://problem/33251668
75 void foo13(...) __attribute__((overloadable));
foo13(...)76 void foo13(...) __attribute__((overloadable)) {}
77
78 // We should not generate a strict-prototype warning for an implicit
79 // declaration. Leave that up to the implicit-function-declaration warning.
foo14(void)80 void foo14(void) {
81 foo14_call(); // no-warning
82 }
83