In legacy environment, a lot of warnings can be issued about arguments without an explicit type. Fix this by contitionalizing such warnings with the flag -Wimplicit-int, reducing the level of noise in such environment. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- lib.c | 2 ++ lib.h | 1 + parse.c | 5 ++++- validation/implicit-KR-arg-type0.c | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 validation/implicit-KR-arg-type0.c diff --git a/lib.c b/lib.c index 818207450..314b65e9f 100644 --- a/lib.c +++ b/lib.c @@ -262,6 +262,7 @@ int Wdeclarationafterstatement = -1; int Wdefault_bitfield_sign = 0; int Wdesignated_init = 1; int Wdo_while = 0; +int Wimplicit_int = 1; int Winit_cstring = 0; int Wint_to_pointer_cast = 1; int Wenum_mismatch = 1; @@ -700,6 +701,7 @@ static const struct flag warnings[] = { { "designated-init", &Wdesignated_init }, { "do-while", &Wdo_while }, { "enum-mismatch", &Wenum_mismatch }, + { "implicit-int", &Wimplicit_int }, { "init-cstring", &Winit_cstring }, { "int-to-pointer-cast", &Wint_to_pointer_cast }, { "memcpy-max-count", &Wmemcpy_max_count }, diff --git a/lib.h b/lib.h index 14b13b676..bd578be52 100644 --- a/lib.h +++ b/lib.h @@ -152,6 +152,7 @@ extern int Wdesignated_init; extern int Wdo_while; extern int Wenum_mismatch; extern int Wsparse_error; +extern int Wimplicit_int; extern int Winit_cstring; extern int Wint_to_pointer_cast; extern int Wmemcpy_max_count; diff --git a/parse.c b/parse.c index 7f15acf58..ec145601d 100644 --- a/parse.c +++ b/parse.c @@ -2770,7 +2770,10 @@ static void apply_k_r_types(struct symbol_list *argtypes, struct symbol *fn) if (type->ident == arg->ident) goto match; } END_FOR_EACH_PTR(type); - sparse_error(arg->pos, "missing type declaration for parameter '%s'", show_ident(arg->ident)); + if (Wimplicit_int) { + sparse_error(arg->pos, "missing type declaration for parameter '%s'", + show_ident(arg->ident)); + } type = alloc_symbol(arg->pos, SYM_NODE); type->ident = arg->ident; type->ctype.base_type = &int_ctype; diff --git a/validation/implicit-KR-arg-type0.c b/validation/implicit-KR-arg-type0.c new file mode 100644 index 000000000..f73d36ffe --- /dev/null +++ b/validation/implicit-KR-arg-type0.c @@ -0,0 +1,15 @@ +int foo(a, b) + int a; +{ + if (b) + return a; +} + +/* + * check-name: implicit-KR-arg-type + * check-command: sparse -Wno-decl -Wold-style-definition -Wno-implicit-int $file + * + * check-error-start +implicit-KR-arg-type0.c:2:9: warning: non-ANSI definition of function 'foo' + * check-error-end + */ -- 2.19.0