diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-11-30 12:43:29 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-12-01 02:12:45 +0100 |
commit | 6f7aa5e84dacec8e27a8d70090bba26a1a1276de (patch) | |
tree | 231184af511c817eb7c40baf20d9758cb1bf4fd3 | |
parent | d3038d8fce94959bc9bcbcff698d272d0f610364 (diff) | |
download | sparse-6f7aa5e84dacec8e27a8d70090bba26a1a1276de.tar.gz |
fix implicit K&R argument types
In an old-style function definition, if not explicitly specified,
the type of an argument defaults to 'int'.
Sparse issues an error for such arguments and leaves the type
as 'incomplete'. This can then create a cascade of other warnings.
Fix this by effectively giving the type 'int' to such arguments.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | parse.c | 4 | ||||
-rw-r--r-- | validation/implicit-KR-arg-type1.c | 16 |
2 files changed, 19 insertions, 1 deletions
@@ -2771,7 +2771,9 @@ static void apply_k_r_types(struct symbol_list *argtypes, struct symbol *fn) goto match; } END_FOR_EACH_PTR(type); sparse_error(arg->pos, "missing type declaration for parameter '%s'", show_ident(arg->ident)); - continue; + type = alloc_symbol(arg->pos, SYM_NODE); + type->ident = arg->ident; + type->ctype.base_type = &int_ctype; match: type->used = 1; /* "char" and "short" promote to "int" */ diff --git a/validation/implicit-KR-arg-type1.c b/validation/implicit-KR-arg-type1.c new file mode 100644 index 00000000..fe199ef5 --- /dev/null +++ b/validation/implicit-KR-arg-type1.c @@ -0,0 +1,16 @@ +int foo(a, b) + int a; +{ + if (b) + 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' + * check-error-end + */ |