[v3,11/11] c: Add new -Wdeclaration-missing-parameter-type permerror
Checks
Commit Message
This used to be a warning, enabled by default, without its own option.
A subsequent change could improve diagnostics and provide spelling
hints for declarations like “void function (int32t);”.
gcc/c-family/
* c.opt (Wdeclaration-missing-parameter-type): New.
gcc/c/ChangeLog:
PR other/44209
* c-decl.cc (grokparms): Issue permerror for
OPT_Wdeclaration_missing_parameter_type instead of a pedwarn.
gcc/ChangeLog:
* doc/invoke.texi (Warning Options): Document
-Wdeclaration-missing-parameter-type.
gcc/testsuite/ChangeLog:
* gcc.dg/permerror-default.c (missing_parameter_type):
Expect error.
* gcc.dg/permerror-fpermissive.c (missing_parameter_type):
Expect -Wdeclaration-missing-parameter-type warning.
* gcc.dg/permerror-gnu89-nopermissive.c (missing_parameter_type):
Expect -Wdeclaration-missing-parameter-type error.
* gcc.dg/permerror-gnu89-pedantic.c (missing_parameter_type):
Likewise.
* gcc.dg/permerror-gnu89.c (missing_parameter_type):
Expect -Wdeclaration-missing-parameter-type warning.
* gcc.dg/permerror-noerror.c: Add
-Wno-error=declaration-missing-parameter-type to build flags.
(missing_parameter_type): Expect
-Wdeclaration-missing-parameter-type warning.
* gcc.dg/permerror-nowarning.c: Build with
-Wno-declaration-missing-parameter-type. Remove previously
expected warning.
* gcc.dg/permerror-fpermissive-nowarning.c: Likewise.
* gcc.dg/permerror-pedantic.c (missing_parameter_type):
Expect -Wdeclaration-missing-parameter-type error.
* gcc.dg/permerror-system.c (missing_parameter_type):
Likewise.
---
gcc/c-family/c.opt | 4 ++++
gcc/c/c-decl.cc | 6 ++++--
gcc/doc/invoke.texi | 17 ++++++++++++++++-
gcc/testsuite/gcc.dg/permerror-default.c | 2 +-
.../gcc.dg/permerror-fpermissive-nowarning.c | 7 +------
gcc/testsuite/gcc.dg/permerror-fpermissive.c | 2 +-
.../gcc.dg/permerror-gnu89-nopermissive.c | 2 +-
gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c | 2 +-
gcc/testsuite/gcc.dg/permerror-gnu89.c | 2 +-
gcc/testsuite/gcc.dg/permerror-noerror.c | 4 ++--
gcc/testsuite/gcc.dg/permerror-nowarning.c | 7 +------
gcc/testsuite/gcc.dg/permerror-pedantic.c | 2 +-
gcc/testsuite/gcc.dg/permerror-system.c | 2 ++
13 files changed, 36 insertions(+), 23 deletions(-)
Comments
On Mon, Nov 20, 2023 at 4:58 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> This used to be a warning, enabled by default, without its own option.
Right, I meant to ask: why create a new option of
-Wdeclaration-missing-parameter-type instead of reusing the existing
-Wmissing-parameter-type for this?
>
> A subsequent change could improve diagnostics and provide spelling
> hints for declarations like “void function (int32t);”.
>
> gcc/c-family/
>
> * c.opt (Wdeclaration-missing-parameter-type): New.
>
> gcc/c/ChangeLog:
>
> PR other/44209
> * c-decl.cc (grokparms): Issue permerror for
> OPT_Wdeclaration_missing_parameter_type instead of a pedwarn.
>
> gcc/ChangeLog:
>
> * doc/invoke.texi (Warning Options): Document
> -Wdeclaration-missing-parameter-type.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/permerror-default.c (missing_parameter_type):
> Expect error.
> * gcc.dg/permerror-fpermissive.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-gnu89-nopermissive.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type error.
> * gcc.dg/permerror-gnu89-pedantic.c (missing_parameter_type):
> Likewise.
> * gcc.dg/permerror-gnu89.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-noerror.c: Add
> -Wno-error=declaration-missing-parameter-type to build flags.
> (missing_parameter_type): Expect
> -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-nowarning.c: Build with
> -Wno-declaration-missing-parameter-type. Remove previously
> expected warning.
> * gcc.dg/permerror-fpermissive-nowarning.c: Likewise.
> * gcc.dg/permerror-pedantic.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type error.
> * gcc.dg/permerror-system.c (missing_parameter_type):
> Likewise.
> ---
> gcc/c-family/c.opt | 4 ++++
> gcc/c/c-decl.cc | 6 ++++--
> gcc/doc/invoke.texi | 17 ++++++++++++++++-
> gcc/testsuite/gcc.dg/permerror-default.c | 2 +-
> .../gcc.dg/permerror-fpermissive-nowarning.c | 7 +------
> gcc/testsuite/gcc.dg/permerror-fpermissive.c | 2 +-
> .../gcc.dg/permerror-gnu89-nopermissive.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-gnu89.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-noerror.c | 4 ++--
> gcc/testsuite/gcc.dg/permerror-nowarning.c | 7 +------
> gcc/testsuite/gcc.dg/permerror-pedantic.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-system.c | 2 ++
> 13 files changed, 36 insertions(+), 23 deletions(-)
>
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index b10c6057cd1..723e8c3e27b 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -591,6 +591,10 @@ Wdeclaration-after-statement
> C ObjC Var(warn_declaration_after_statement) Init(-1) Warning
> Warn when a declaration is found after a statement.
>
> +Wdeclaration-missing-parameter-type
> +C ObjC Var(warn_declaration_missing_parameter) Warning Init(1)
> +Warn for missing parameter types in function declarations.
> +
> Wdelete-incomplete
> C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning
> Warn when deleting a pointer to incomplete type.
> diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
> index d16958113a8..3d9bee54259 100644
> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -8337,8 +8337,10 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
> {
> if (!funcdef_flag)
> {
> - pedwarn (input_location, 0, "parameter names (without types) in "
> - "function declaration");
> + permerror_opt (input_location,
> + OPT_Wdeclaration_missing_parameter_type,
> + "parameter names (without types) in "
> + "function declaration");
> arg_info->parms = NULL_TREE;
> }
> else
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index be33da71c44..7f5da45dcea 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -504,7 +504,8 @@ Objective-C and Objective-C++ Dialects}.
>
> @item C and Objective-C-only Warning Options
> @gccoptlist{-Wbad-function-cast -Wmissing-declarations
> --Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarations
> +-Wmissing-parameter-type -Wdeclaration-missing-parameter-type
> +-Wmissing-prototypes -Wmissing-variable-declarations
> -Wnested-externs -Wold-style-declaration -Wold-style-definition
> -Wstrict-prototypes -Wtraditional -Wtraditional-conversion
> -Wdeclaration-after-statement -Wpointer-sign}
> @@ -9734,6 +9735,20 @@ void foo(bar) @{ @}
>
> This warning is also enabled by @option{-Wextra}.
>
> +@opindex Wno-declaration-missing-parameter-type
> +@opindex Wdeclaration-missing-parameter-type
> +@item -Wno-declaration-missing-parameter-type @r{(C and Objective-C only)}
> +Do not warn if a function declaration contains a parameter name without
> +a type. Such function declarations do not provide a function prototype
> +and prevent most type checking in function calls.
> +
> +This warning is enabled by default. In C99 and later dialects of C, it
> +is treated as an error. The error can be downgraded to a warning using
> +@option{-fpermissive} (along with certain other errors), or for this
> +error alone, with @option{-Wno-error=declaration-missing-parameter-type}.
> +
> +This warning is upgraded to an error by @option{-pedantic-errors}.
> +
> @opindex Wmissing-prototypes
> @opindex Wno-missing-prototypes
> @item -Wmissing-prototypes @r{(C and Objective-C only)}
> diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c
> index 45b58b0131d..c674d689081 100644
> --- a/gcc/testsuite/gcc.dg/permerror-default.c
> +++ b/gcc/testsuite/gcc.dg/permerror-default.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
> (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> index f15b21ef43d..d07c8636677 100644
> --- a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> @@ -1,11 +1,6 @@
> -/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
> +/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
>
> /* This test checks that permerrors can be disabled using -Wno-* options even
> if -fpermissive is used. */
>
> #include "permerror-default.c"
> -
> -/* Ideally, we do not want to see any warnings here, but this warning is not
> - yet controlled by its own option. */
> -
> -/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
> diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> index 139f35ad1c0..fd3020d75ee 100644
> --- a/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
> (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> index 93504b94139..aba4b2498f7 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> index 465a16f5f9a..ef4dbfc86c5 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89.c b/gcc/testsuite/gcc.dg/permerror-gnu89.c
> index 66f7789269f..83792ecfaac 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.dg/permerror-noerror.c
> index cd1c2013cb5..fc68dfa8bb9 100644
> --- a/gcc/testsuite/gcc.dg/permerror-noerror.c
> +++ b/gcc/testsuite/gcc.dg/permerror-noerror.c
> @@ -1,4 +1,4 @@
> -/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */
> +/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch -Wno-error=declaration-missing-parameter-type" } */
>
> /* This test should emulate the effect of -fpermissive by adding all the
> -Wno-error= options that are implied by -fpermissive. It needs to be
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
> (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-nowarning.c b/gcc/testsuite/gcc.dg/permerror-nowarning.c
> index da6bd08245d..b1cf7990127 100644
> --- a/gcc/testsuite/gcc.dg/permerror-nowarning.c
> +++ b/gcc/testsuite/gcc.dg/permerror-nowarning.c
> @@ -1,10 +1,5 @@
> -/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
> +/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
>
> /* This test checks that permerrors can be disabled using -Wno-* options. */
>
> #include "permerror-default.c"
> -
> -/* Ideally, we do not want to see any warnings here, but this warning is not
> - yet controlled by its own option. */
> -
> -/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
> diff --git a/gcc/testsuite/gcc.dg/permerror-pedantic.c b/gcc/testsuite/gcc.dg/permerror-pedantic.c
> index 95dda18acd4..2380bb2583c 100644
> --- a/gcc/testsuite/gcc.dg/permerror-pedantic.c
> +++ b/gcc/testsuite/gcc.dg/permerror-pedantic.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
> (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c
> index bd923138461..790e4f03d66 100644
> --- a/gcc/testsuite/gcc.dg/permerror-system.c
> +++ b/gcc/testsuite/gcc.dg/permerror-system.c
> @@ -17,6 +17,8 @@
> /* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} 16 } */
> /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" "" { target *-*-* } 19 } */
>
> +/* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" "" { target *-*-* } 22 } */
> +
> /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 29 } */
> /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 30 } */
> /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */
> --
> 2.42.0
>
* Eric Gallager:
> On Mon, Nov 20, 2023 at 4:58 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> This used to be a warning, enabled by default, without its own option.
>
> Right, I meant to ask: why create a new option of
> -Wdeclaration-missing-parameter-type instead of reusing the existing
> -Wmissing-parameter-type for this?
It's documented as:
‘-Wmissing-parameter-type (C and Objective-C only)’
A function parameter is declared without a type specifier in
K&R-style functions:
void foo(bar) { }
This warning is also enabled by ‘-Wextra’.
What this doesn't say is that this has been subsumed by -Wimplicit-int
in C99 and later language modes.
Maybe we can tweak things such that -Wmissing-parameter-type controls
declarations only in C99 and later language modes, and turn just that
into a permerror. But the situation is confusing enough already, which
is why I opted for the separate warning.
Thanks,
Florian
On Mon, Nov 20, 2023 at 10:56:42AM +0100, Florian Weimer wrote:
> This used to be a warning, enabled by default, without its own option.
I think this patch is OK now.
> A subsequent change could improve diagnostics and provide spelling
> hints for declarations like “void function (int32t);”.
Feel free to open a PR.
> gcc/c-family/
>
> * c.opt (Wdeclaration-missing-parameter-type): New.
>
> gcc/c/ChangeLog:
>
> PR other/44209
FWIW, these usually go before the whole ChangeLog entry.
Thanks, and sorry about the wait.
> * c-decl.cc (grokparms): Issue permerror for
> OPT_Wdeclaration_missing_parameter_type instead of a pedwarn.
>
> gcc/ChangeLog:
>
> * doc/invoke.texi (Warning Options): Document
> -Wdeclaration-missing-parameter-type.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/permerror-default.c (missing_parameter_type):
> Expect error.
> * gcc.dg/permerror-fpermissive.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-gnu89-nopermissive.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type error.
> * gcc.dg/permerror-gnu89-pedantic.c (missing_parameter_type):
> Likewise.
> * gcc.dg/permerror-gnu89.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-noerror.c: Add
> -Wno-error=declaration-missing-parameter-type to build flags.
> (missing_parameter_type): Expect
> -Wdeclaration-missing-parameter-type warning.
> * gcc.dg/permerror-nowarning.c: Build with
> -Wno-declaration-missing-parameter-type. Remove previously
> expected warning.
> * gcc.dg/permerror-fpermissive-nowarning.c: Likewise.
> * gcc.dg/permerror-pedantic.c (missing_parameter_type):
> Expect -Wdeclaration-missing-parameter-type error.
> * gcc.dg/permerror-system.c (missing_parameter_type):
> Likewise.
> ---
> gcc/c-family/c.opt | 4 ++++
> gcc/c/c-decl.cc | 6 ++++--
> gcc/doc/invoke.texi | 17 ++++++++++++++++-
> gcc/testsuite/gcc.dg/permerror-default.c | 2 +-
> .../gcc.dg/permerror-fpermissive-nowarning.c | 7 +------
> gcc/testsuite/gcc.dg/permerror-fpermissive.c | 2 +-
> .../gcc.dg/permerror-gnu89-nopermissive.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-gnu89.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-noerror.c | 4 ++--
> gcc/testsuite/gcc.dg/permerror-nowarning.c | 7 +------
> gcc/testsuite/gcc.dg/permerror-pedantic.c | 2 +-
> gcc/testsuite/gcc.dg/permerror-system.c | 2 ++
> 13 files changed, 36 insertions(+), 23 deletions(-)
>
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index b10c6057cd1..723e8c3e27b 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -591,6 +591,10 @@ Wdeclaration-after-statement
> C ObjC Var(warn_declaration_after_statement) Init(-1) Warning
> Warn when a declaration is found after a statement.
>
> +Wdeclaration-missing-parameter-type
> +C ObjC Var(warn_declaration_missing_parameter) Warning Init(1)
> +Warn for missing parameter types in function declarations.
> +
> Wdelete-incomplete
> C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning
> Warn when deleting a pointer to incomplete type.
> diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
> index d16958113a8..3d9bee54259 100644
> --- a/gcc/c/c-decl.cc
> +++ b/gcc/c/c-decl.cc
> @@ -8337,8 +8337,10 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
> {
> if (!funcdef_flag)
> {
> - pedwarn (input_location, 0, "parameter names (without types) in "
> - "function declaration");
> + permerror_opt (input_location,
> + OPT_Wdeclaration_missing_parameter_type,
> + "parameter names (without types) in "
> + "function declaration");
> arg_info->parms = NULL_TREE;
> }
> else
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index be33da71c44..7f5da45dcea 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -504,7 +504,8 @@ Objective-C and Objective-C++ Dialects}.
>
> @item C and Objective-C-only Warning Options
> @gccoptlist{-Wbad-function-cast -Wmissing-declarations
> --Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarations
> +-Wmissing-parameter-type -Wdeclaration-missing-parameter-type
> +-Wmissing-prototypes -Wmissing-variable-declarations
> -Wnested-externs -Wold-style-declaration -Wold-style-definition
> -Wstrict-prototypes -Wtraditional -Wtraditional-conversion
> -Wdeclaration-after-statement -Wpointer-sign}
> @@ -9734,6 +9735,20 @@ void foo(bar) @{ @}
>
> This warning is also enabled by @option{-Wextra}.
>
> +@opindex Wno-declaration-missing-parameter-type
> +@opindex Wdeclaration-missing-parameter-type
> +@item -Wno-declaration-missing-parameter-type @r{(C and Objective-C only)}
> +Do not warn if a function declaration contains a parameter name without
> +a type. Such function declarations do not provide a function prototype
> +and prevent most type checking in function calls.
> +
> +This warning is enabled by default. In C99 and later dialects of C, it
> +is treated as an error. The error can be downgraded to a warning using
> +@option{-fpermissive} (along with certain other errors), or for this
> +error alone, with @option{-Wno-error=declaration-missing-parameter-type}.
> +
> +This warning is upgraded to an error by @option{-pedantic-errors}.
> +
> @opindex Wmissing-prototypes
> @opindex Wno-missing-prototypes
> @item -Wmissing-prototypes @r{(C and Objective-C only)}
> diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c
> index 45b58b0131d..c674d689081 100644
> --- a/gcc/testsuite/gcc.dg/permerror-default.c
> +++ b/gcc/testsuite/gcc.dg/permerror-default.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
> (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> index f15b21ef43d..d07c8636677 100644
> --- a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
> @@ -1,11 +1,6 @@
> -/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
> +/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
>
> /* This test checks that permerrors can be disabled using -Wno-* options even
> if -fpermissive is used. */
>
> #include "permerror-default.c"
> -
> -/* Ideally, we do not want to see any warnings here, but this warning is not
> - yet controlled by its own option. */
> -
> -/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
> diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> index 139f35ad1c0..fd3020d75ee 100644
> --- a/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> +++ b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
> (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> index 93504b94139..aba4b2498f7 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> index 465a16f5f9a..ef4dbfc86c5 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89.c b/gcc/testsuite/gcc.dg/permerror-gnu89.c
> index 66f7789269f..83792ecfaac 100644
> --- a/gcc/testsuite/gcc.dg/permerror-gnu89.c
> +++ b/gcc/testsuite/gcc.dg/permerror-gnu89.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
> (const) 0; /* { dg-bogus "-Wimplicit-int" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.dg/permerror-noerror.c
> index cd1c2013cb5..fc68dfa8bb9 100644
> --- a/gcc/testsuite/gcc.dg/permerror-noerror.c
> +++ b/gcc/testsuite/gcc.dg/permerror-noerror.c
> @@ -1,4 +1,4 @@
> -/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */
> +/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch -Wno-error=declaration-missing-parameter-type" } */
>
> /* This test should emulate the effect of -fpermissive by adding all the
> -Wno-error= options that are implied by -fpermissive. It needs to be
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
> (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-nowarning.c b/gcc/testsuite/gcc.dg/permerror-nowarning.c
> index da6bd08245d..b1cf7990127 100644
> --- a/gcc/testsuite/gcc.dg/permerror-nowarning.c
> +++ b/gcc/testsuite/gcc.dg/permerror-nowarning.c
> @@ -1,10 +1,5 @@
> -/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
> +/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
>
> /* This test checks that permerrors can be disabled using -Wno-* options. */
>
> #include "permerror-default.c"
> -
> -/* Ideally, we do not want to see any warnings here, but this warning is not
> - yet controlled by its own option. */
> -
> -/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
> diff --git a/gcc/testsuite/gcc.dg/permerror-pedantic.c b/gcc/testsuite/gcc.dg/permerror-pedantic.c
> index 95dda18acd4..2380bb2583c 100644
> --- a/gcc/testsuite/gcc.dg/permerror-pedantic.c
> +++ b/gcc/testsuite/gcc.dg/permerror-pedantic.c
> @@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
> (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
> }
>
> -extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
> +extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
>
>
> int *
> diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c
> index bd923138461..790e4f03d66 100644
> --- a/gcc/testsuite/gcc.dg/permerror-system.c
> +++ b/gcc/testsuite/gcc.dg/permerror-system.c
> @@ -17,6 +17,8 @@
> /* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} 16 } */
> /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" "" { target *-*-* } 19 } */
>
> +/* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" "" { target *-*-* } 22 } */
> +
> /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 29 } */
> /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 30 } */
> /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */
> --
> 2.42.0
>
Marek
* Marek Polacek:
> On Mon, Nov 20, 2023 at 10:56:42AM +0100, Florian Weimer wrote:
>> This used to be a warning, enabled by default, without its own option.
>
> I think this patch is OK now.
>
>> A subsequent change could improve diagnostics and provide spelling
>> hints for declarations like “void function (int32t);”.
>
> Feel free to open a PR.
Good idea, it's now:
Spelling hint for typos in parameter types in function prototypes
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112954>
Thanks,
Florian
@@ -591,6 +591,10 @@ Wdeclaration-after-statement
C ObjC Var(warn_declaration_after_statement) Init(-1) Warning
Warn when a declaration is found after a statement.
+Wdeclaration-missing-parameter-type
+C ObjC Var(warn_declaration_missing_parameter) Warning Init(1)
+Warn for missing parameter types in function declarations.
+
Wdelete-incomplete
C++ ObjC++ Var(warn_delete_incomplete) Init(1) Warning
Warn when deleting a pointer to incomplete type.
@@ -8337,8 +8337,10 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
{
if (!funcdef_flag)
{
- pedwarn (input_location, 0, "parameter names (without types) in "
- "function declaration");
+ permerror_opt (input_location,
+ OPT_Wdeclaration_missing_parameter_type,
+ "parameter names (without types) in "
+ "function declaration");
arg_info->parms = NULL_TREE;
}
else
@@ -504,7 +504,8 @@ Objective-C and Objective-C++ Dialects}.
@item C and Objective-C-only Warning Options
@gccoptlist{-Wbad-function-cast -Wmissing-declarations
--Wmissing-parameter-type -Wmissing-prototypes -Wmissing-variable-declarations
+-Wmissing-parameter-type -Wdeclaration-missing-parameter-type
+-Wmissing-prototypes -Wmissing-variable-declarations
-Wnested-externs -Wold-style-declaration -Wold-style-definition
-Wstrict-prototypes -Wtraditional -Wtraditional-conversion
-Wdeclaration-after-statement -Wpointer-sign}
@@ -9734,6 +9735,20 @@ void foo(bar) @{ @}
This warning is also enabled by @option{-Wextra}.
+@opindex Wno-declaration-missing-parameter-type
+@opindex Wdeclaration-missing-parameter-type
+@item -Wno-declaration-missing-parameter-type @r{(C and Objective-C only)}
+Do not warn if a function declaration contains a parameter name without
+a type. Such function declarations do not provide a function prototype
+and prevent most type checking in function calls.
+
+This warning is enabled by default. In C99 and later dialects of C, it
+is treated as an error. The error can be downgraded to a warning using
+@option{-fpermissive} (along with certain other errors), or for this
+error alone, with @option{-Wno-error=declaration-missing-parameter-type}.
+
+This warning is upgraded to an error by @option{-pedantic-errors}.
+
@opindex Wmissing-prototypes
@opindex Wno-missing-prototypes
@item -Wmissing-prototypes @r{(C and Objective-C only)}
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
(const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
}
-extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -1,11 +1,6 @@
-/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
+/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
/* This test checks that permerrors can be disabled using -Wno-* options even
if -fpermissive is used. */
#include "permerror-default.c"
-
-/* Ideally, we do not want to see any warnings here, but this warning is not
- yet controlled by its own option. */
-
-/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
(const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
}
-extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
(const) 0; /* { dg-bogus "-Wimplicit-int" } */
}
-extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
(const) 0; /* { dg-bogus "-Wimplicit-int" } */
}
-extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
(const) 0; /* { dg-bogus "-Wimplicit-int" } */
}
-extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -1,4 +1,4 @@
-/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */
+/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch -Wno-error=declaration-missing-parameter-type" } */
/* This test should emulate the effect of -fpermissive by adding all the
-Wno-error= options that are implied by -fpermissive. It needs to be
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit
(const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
}
-extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -1,10 +1,5 @@
-/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
+/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch -Wno-declaration-missing-parameter-type" } */
/* This test checks that permerrors can be disabled using -Wno-* options. */
#include "permerror-default.c"
-
-/* Ideally, we do not want to see any warnings here, but this warning is not
- yet controlled by its own option. */
-
-/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
@@ -19,7 +19,7 @@ implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-i
(const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
}
-extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" } */
int *
@@ -17,6 +17,8 @@
/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} 16 } */
/* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" "" { target *-*-* } 19 } */
+/* { dg-error "parameter names \\\(without types\\\) in function declaration \\\[-Wdeclaration-missing-parameter-type\\\]" "" { target *-*-* } 22 } */
+
/* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 29 } */
/* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" "" { target *-*-* } 30 } */
/* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" "" { target *-*-* } 31 } */