brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.9 KiB · 170e80d Raw
108 lines · c
1// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -Wno-deprecated-non-prototype -verify %s2// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes -Wno-deprecated-non-prototype -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s3 4int 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]]:{{.*}}}:"{{.*}}"6 7int f(int x) { return x; } // expected-warning{{no previous prototype for function 'f'}}8 9static int g(int x) { return x; }10 11int 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 "14 15static int g2();16 17int g2(int x) { return x; }18 19extern 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]]:{{.*}}}:"{{.*}}"22 23void test(void);24 25int 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]]:{{.*}}}:"{{.*}}"27int h4(int);28int h4();29 30void test(void) {31  int h2(int x);32  int h3(int x);33  int h4();34}35 36int 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}}38int h3(int x) { return x; } // expected-warning{{no previous prototype for function 'h3'}}39int h4(int x) { return x; }40 41int f2(int);42int f2();43 44int f2(int x) { return x; }45 46int main(void) { return 0; }47 48void 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"50void not_a_prototype_test() { } // expected-warning{{no previous prototype for function 'not_a_prototype_test'}}51 52const 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 "55  return (void *)0;56}57 58struct MyStruct {};59 60const 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 "63  struct MyStruct ret;64  return ret;65}66 67// Turn off clang-format for white-space dependent testing.68// clang-format off69// Two spaces between cost and struct70const  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 "73  struct MyStruct ret;74  return ret;75}76 77// Two spaces bewteen const and struct78const  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 "81  return (void*)0;82}83 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 "88  return (void*)0;89}90 91// Random comment after const.92const/*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 "95  return (void*)0;96}97// clang-format on98 99#define MY_CONST const100 101// Since we can't easily understand what MY_CONST means while preparing the102// diagnostic, the fix-it suggests to add 'static' in a non-idiomatic place.103MY_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 "106  return (void *)0;107}108