|
| 1 | +// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify %s |
| 2 | +// RUN: %clang_cc1 -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 |
| 12 | +void foo1() {} |
| 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 |
| 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 |
| 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 |
| 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 |
| 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); |
| 62 | +void foo11(p, p2) int p; int p2; {} |
0 commit comments