public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, jeffreyalaw@gmail.com, joseph@codesourcery.com,
	sam@gentoo.org
Subject: [PATCH v2 8/8] c: Add new -Wdeclaration-missing-parameter-type permerror
Date: Tue, 14 Nov 2023 18:50:58 +0100	[thread overview]
Message-ID: <a5f0cb7b4691598e5f61634f08d162f5d7e90d38.1699983736.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1699983736.git.fweimer@redhat.com>

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-pedantic.c (missing_parameter_type):
	Expect -Wdeclaration-missing-parameter-type error.
	* 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-pedantic.c (missing_parameter_type):
	Expect -Wdeclaration-missing-parameter-type error.
---
 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/testsuite/gcc.dg/permerror-fpermissive.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-pedantic.c       |  2 +-
 gcc/testsuite/gcc.dg/permerror-system.c         |  2 ++
 10 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index b10c6057cd1..723985ec5d0 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 Warning
+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 c492ef7ba0c..66804bfe120 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -502,7 +502,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}
@@ -9732,6 +9733,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.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-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-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.41.0


  parent reply	other threads:[~2023-11-14 17:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 17:50 [PATCH v2 0/8] Turn some C warnings into errors by default Florian Weimer
2023-11-14 17:50 ` [PATCH v2 1/8] Add tests for validating future C permerrors Florian Weimer
2023-11-14 17:50 ` [PATCH v2 2/8] c: Turn int-conversion warnings into permerrors Florian Weimer
2023-11-14 17:50 ` [PATCH v2 3/8] c: Turn -Wimplicit-function-declaration into a permerror Florian Weimer
2023-11-14 17:50 ` [PATCH v2 4/8] c: Turn -Wimplicit-int " Florian Weimer
2023-11-14 17:50 ` [PATCH v2 5/8] c: Do not ignore some forms of -Wimplicit-int in system headers Florian Weimer
2023-11-15  5:03   ` Sam James
2023-11-15  5:12     ` Florian Weimer
2023-11-15  5:13       ` Sam James
2023-11-21 21:18         ` Jason Merrill
2023-11-14 17:50 ` [PATCH v2 6/8] c: Turn -Wreturn-mismatch into a permerror Florian Weimer
2023-11-14 17:50 ` [PATCH v2 7/8] c: Turn -Wincompatible-pointer-types " Florian Weimer
2023-11-14 17:50 ` Florian Weimer [this message]
2023-11-14 20:26   ` [PATCH v2 8/8] c: Add new -Wdeclaration-missing-parameter-type permerror Marek Polacek
2023-11-14 22:27     ` Florian Weimer
2023-11-15  5:16 ` [PATCH v2 0/8] Turn some C warnings into errors by default Sam James
2023-11-15  6:37   ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5f0cb7b4691598e5f61634f08d162f5d7e90d38.1699983736.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=joseph@codesourcery.com \
    --cc=sam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).