1 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -Wno-deprecated-non-prototype -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -Wno-deprecated-non-prototype -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
4 int f(); // expected-note{{this declaration is not a prototype; add parameter declarations to make it one}}
5 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:{{.*}}-[[@LINE-1]]:{{.*}}}:"{{.*}}"
7 int f(int x
) { return x
; } // expected-warning{{no previous prototype for function 'f'}}
9 static int g(int x
) { return x
; }
11 int h(int x
) { return x
; } // expected-warning{{no previous prototype for function 'h'}}
12 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
13 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
17 int g2(int x
) { return x
; }
19 extern int g3(int x
) { return x
; } // expected-warning{{no previous prototype for function 'g3'}}
20 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
21 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:{{.*}}-[[@LINE-2]]:{{.*}}}:"{{.*}}"
25 int h3(); // expected-note{{this declaration is not a prototype; add parameter declarations to make it one}}
26 // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:{{.*}}-[[@LINE-1]]:{{.*}}}:"{{.*}}"
36 int h2(int x
) { return x
; } // expected-warning{{no previous prototype for function 'h2'}}
37 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
38 int h3(int x
) { return x
; } // expected-warning{{no previous prototype for function 'h3'}}
39 int h4(int x
) { return x
; }
44 int f2(int x
) { return x
; }
46 int main(void) { return 0; }
48 void not_a_prototype_test(); // expected-note{{this declaration is not a prototype; add 'void' to make it a prototype for a zero-parameter function}}
49 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:27-[[@LINE-1]]:27}:"void"
50 void not_a_prototype_test() { } // expected-warning{{no previous prototype for function 'not_a_prototype_test'}}
52 const int *get_const() { // expected-warning{{no previous prototype for function 'get_const'}}
53 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
54 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
60 const struct MyStruct
get_struct() { // expected-warning{{no previous prototype for function 'get_struct'}}
61 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
62 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
67 // Turn off clang-format for white-space dependent testing.
69 // Two spaces between cost and struct
70 const struct MyStruct
get_struct_2() { // expected-warning{{no previous prototype for function 'get_struct_2'}}
71 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
72 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
77 // Two spaces bewteen const and struct
78 const struct MyStruct
* get_struct_ptr() { // expected-warning{{no previous prototype for function 'get_struct_ptr'}}
79 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
80 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
84 // Random comment before const.
85 /*some randome comment*/const struct MyStruct
* get_struct_3() { // expected-warning{{no previous prototype for function 'get_struct_3'}}
86 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
87 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:25-[[@LINE-2]]:25}:"static "
91 // Random comment after const.
92 const/*some randome comment*/ struct MyStruct
* get_struct_4() { // expected-warning{{no previous prototype for function 'get_struct_4'}}
93 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
94 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:1-[[@LINE-2]]:1}:"static "
99 #define MY_CONST const
101 // Since we can't easily understand what MY_CONST means while preparing the
102 // diagnostic, the fix-it suggests to add 'static' in a non-idiomatic place.
103 MY_CONST
struct MyStruct
*get_struct_nyi() { // expected-warning{{no previous prototype for function 'get_struct_nyi'}}
104 // expected-note@-1{{declare 'static' if the function is not intended to be used outside of this translation unit}}
105 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:10-[[@LINE-2]]:10}:"static "