diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:52:18 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:52:18 +0000 |
| commit | 840f8df67759b6893b6e58d2eb08124cb5822525 (patch) | |
| tree | 2a274e96cee6ac5da2847e68f735307e36e99baa /clang/test | |
| parent | 32d5aedd5be8e7f031525af31208d7ea8905945e (diff) | |
| download | bcm5719-llvm-840f8df67759b6893b6e58d2eb08124cb5822525.tar.gz bcm5719-llvm-840f8df67759b6893b6e58d2eb08124cb5822525.zip | |
Implement the -Wstrict-prototypes warning
This commit fixes PR20796. It implements the C only -Wstrict-prototypes warning.
Clang now emits a warning for function declarations which have no parameters
specified and for K&R function definitions with more than 0 parameters that are
not preceded by a previous prototype declaration.
The patch was originally submitted by Paul Titei!
rdar://15060615
Differential Revision: https://reviews.llvm.org/D16533
llvm-svn: 288896
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Sema/warn-strict-prototypes.c | 62 | ||||
| -rw-r--r-- | clang/test/Sema/warn-strict-prototypes.m | 20 |
2 files changed, 82 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-strict-prototypes.c b/clang/test/Sema/warn-strict-prototypes.c new file mode 100644 index 00000000000..496579c1f60 --- /dev/null +++ b/clang/test/Sema/warn-strict-prototypes.c @@ -0,0 +1,62 @@ +// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s + +// function declaration with unspecified params +void foo1(); // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void" +// function declaration with 0 params +void foo2(void); + +// function definition with 0 params(for both cases), +// valid according to 6.7.5.3/14 +void foo1() {} +void foo2(void) {} + +// function type typedef unspecified params +typedef void foo3(); // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void" + +// global fp unspecified params +void (*foo4)(); // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void" + +// struct member fp unspecified params +struct { void (*foo5)(); } s; // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void" + +// param fp unspecified params +void bar2(void (*foo6)()) { // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void" + // local fp unspecified params + void (*foo7)() = 0; // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void" + // array fp unspecified params + void (*foo8[2])() = {0}; // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void" +} + +// function type cast using using an anonymous function declaration +void bar3(void) { + // casting function w/out prototype to unspecified params function type + (void)(void(*)()) foo1; // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void" + // .. specified params + (void)(void(*)(void)) foo1; +} + +// K&R function definition not preceded by full prototype +int foo9(a, b) // expected-warning {{old-style function definition is not preceded by a prototype}} + int a, b; +{ + return a + b; +} + +// Function declaration with no types +void foo10(); // expected-warning {{this function declaration is not a prototype}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:12}:"void" +// K&R function definition with incomplete param list declared +void foo10(p, p2) void *p; {} // expected-warning {{old-style function definition is not preceded by a prototype}} + +// K&R function definition with previous prototype declared is not diagnosed. +void foo11(int p, int p2); +void foo11(p, p2) int p; int p2; {} diff --git a/clang/test/Sema/warn-strict-prototypes.m b/clang/test/Sema/warn-strict-prototypes.m new file mode 100644 index 00000000000..cbb01a1f7b2 --- /dev/null +++ b/clang/test/Sema/warn-strict-prototypes.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -fblocks %s + +@interface Foo + +@property (nonatomic, copy) void (^noProtoBlock)(); // expected-warning {{this function declaration is not a prototype}} +@property (nonatomic, copy) void (^block)(void); // no warning + +- doStuff:(void (^)()) completionHandler; // expected-warning {{this function declaration is not a prototype}} +- doOtherStuff:(void (^)(void)) completionHandler; // no warning + +@end + +void foo() { + void (^block)() = // expected-warning {{this function declaration is not a prototype}} + ^void(int arg) { // no warning + }; + void (^block2)(void) = // no warning + ^void() { // expected-warning {{this function declaration is not a prototype}} + }; +} |

