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