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@xxxxxxxxx> --- parse.c | 4 +++- validation/implicit-KR-arg-type1.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 validation/implicit-KR-arg-type1.c diff --git a/parse.c b/parse.c index d4886c41c..7f15acf58 100644 --- a/parse.c +++ b/parse.c @@ -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 000000000..fe199ef52 --- /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 + */ -- 2.19.0