diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-03-31 21:46:59 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-22 07:25:43 +0200 |
| commit | 04c3c1e16a2bfcf9231c52d37611f05741056e6a (patch) | |
| tree | 93476f8b7c3cae65766d2378e302898e0b197256 /validation | |
| parent | cfca7b4c6cb48283cb554fc91dc859ff669f2547 (diff) | |
| download | sparse-dev-04c3c1e16a2bfcf9231c52d37611f05741056e6a.tar.gz | |
warn on all missing parameter types
A warning is given for K&R parameters without type declaration
and these parameters are given an implicit type of int to
avoid several problems with false errors in the next stages.
However, this is only done for K&R functions with the optional
parameter type declarations. If the parameters has no type
declaration at all, no diagnostic is given and the type is left
as incomplete. In consequence, a function defined with a typo like
'int foo(oid)' instead of 'int foo(void)' is left undetected
(even with -Wold-style-definition and -Wstrict-prototypes enabled).
Fix this by:
1) adding the type check to declare_argument() so that
all parameters have a real type.
2) downgrade the diagnostic to a warning for K&R functions.
Fixes: 6f7aa5e84dacec8e27a8d70090bba26a1a1276de
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/asm-bad0.c | 2 | ||||
| -rw-r--r-- | validation/bad-type-twice0.c | 3 | ||||
| -rw-r--r-- | validation/badtype2.c | 1 | ||||
| -rw-r--r-- | validation/badtype3.c | 1 | ||||
| -rw-r--r-- | validation/implicit-KR-arg-type1.c | 11 |
5 files changed, 13 insertions, 5 deletions
diff --git a/validation/asm-bad0.c b/validation/asm-bad0.c index aa9bf28d..4ba78575 100644 --- a/validation/asm-bad0.c +++ b/validation/asm-bad0.c @@ -16,7 +16,7 @@ static void icons(void) asm("template" : [out] "=r" (var): [in] string (0)); } -static void oexpr(oid) +static void oexpr(void) { asm("template" : [out] "=" (var[) : [in] "r" (0)); } diff --git a/validation/bad-type-twice0.c b/validation/bad-type-twice0.c index 9e834d47..e7ec7b75 100644 --- a/validation/bad-type-twice0.c +++ b/validation/bad-type-twice0.c @@ -7,7 +7,6 @@ static int foo(a) * check-name: bad-type-twice0 * * check-error-start -bad-type-twice0.c:3:16: error: non-scalar type in conditional: -bad-type-twice0.c:3:16: incomplete type a +bad-type-twice0.c:1:16: error: missing type declaration for parameter 'a' * check-error-end */ diff --git a/validation/badtype2.c b/validation/badtype2.c index 49fec87c..173dbfda 100644 --- a/validation/badtype2.c +++ b/validation/badtype2.c @@ -18,6 +18,7 @@ badtype2.c:2:14: error: got bar badtype2.c:3:14: error: Expected ; at end of declaration badtype2.c:3:14: error: got foo badtype2.c:6:3: error: Trying to use reserved word 'switch' as identifier +badtype2.c:6:11: error: missing type declaration for parameter 'p' badtype2.c:7:3: error: not in switch scope badtype2.c:10:1: error: Expected ; at the end of type declaration badtype2.c:10:1: error: got } diff --git a/validation/badtype3.c b/validation/badtype3.c index 20f346c5..c111d94e 100644 --- a/validation/badtype3.c +++ b/validation/badtype3.c @@ -16,6 +16,7 @@ badtype3.c:2:18: warning: identifier list not in definition badtype3.c:2:24: error: Expected ) in function declarator badtype3.c:2:24: error: got , badtype3.c:5:3: error: Trying to use reserved word 'while' as identifier +badtype3.c:5:10: error: missing type declaration for parameter 'cur' badtype3.c:7:7: error: break/continue not in iterator scope badtype3.c:9:3: error: Trying to use reserved word 'return' as identifier badtype3.c:9:10: error: Expected ; at end of declaration diff --git a/validation/implicit-KR-arg-type1.c b/validation/implicit-KR-arg-type1.c index fe199ef5..c7eb39ae 100644 --- a/validation/implicit-KR-arg-type1.c +++ b/validation/implicit-KR-arg-type1.c @@ -1,16 +1,23 @@ -int foo(a, b) +static int foo(a, b) int a; { if (b) return a; } +static int bar(a) +{ + if (a) + return a; +} + /* * check-name: implicit-KR-arg-type1 * check-command: sparse -Wold-style-definition -Wimplicit-int $file * * check-error-start implicit-KR-arg-type1.c:2:9: warning: non-ANSI definition of function 'foo' -implicit-KR-arg-type1.c:1:12: error: missing type declaration for parameter 'b' +implicit-KR-arg-type1.c:1:19: warning: missing type declaration for parameter 'b' +implicit-KR-arg-type1.c:8:16: error: missing type declaration for parameter 'a' * check-error-end */ |
