public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Warn about variadic functions defined without prototypes (PR c/68024)
@ 2015-10-21 16:23 Marek Polacek
  2015-10-21 17:17 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2015-10-21 16:23 UTC (permalink / raw)
  To: GCC Patches, Joseph Myers

Joseph, is this what you had in mind in this PR?  With this patch, we
warn anytime we see a prototype-less function that is variadic.  It
seems rare enough not to warrant a separate warning option for it.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-10-21  Marek Polacek  <polacek@redhat.com>

	PR c/68024
	* c-decl.c (start_function): Warn about vararg functions without
	a prototype.

	* gcc.dg/pr68024.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index ce8406a..4a0e090 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -8328,6 +8328,12 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
 	  && comptypes (TREE_TYPE (TREE_TYPE (decl1)),
 			TREE_TYPE (TREE_TYPE (old_decl))))
 	{
+	  if (stdarg_p (TREE_TYPE (old_decl)))
+	    {
+	      warning_at (loc, 0, "%q+D defined as variadic function "
+			  "without prototype", decl1);
+	      locate_old_decl (old_decl);
+	    }
 	  TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl),
 					      TREE_TYPE (decl1));
 	  current_function_prototype_locus = DECL_SOURCE_LOCATION (old_decl);
diff --git gcc/testsuite/gcc.dg/pr68024.c gcc/testsuite/gcc.dg/pr68024.c
index e69de29..a750917 100644
--- gcc/testsuite/gcc.dg/pr68024.c
+++ gcc/testsuite/gcc.dg/pr68024.c
@@ -0,0 +1,5 @@
+/* PR c/68024 */
+/* { dg-do compile } */
+
+void f (int, ...);
+void f (a) int a; {} /* { dg-warning "defined as variadic function without prototype" } */

	Marek

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C PATCH] Warn about variadic functions defined without prototypes (PR c/68024)
  2015-10-21 16:23 [C PATCH] Warn about variadic functions defined without prototypes (PR c/68024) Marek Polacek
@ 2015-10-21 17:17 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2015-10-21 17:17 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Wed, 21 Oct 2015, Marek Polacek wrote:

> Joseph, is this what you had in mind in this PR?  With this patch, we
> warn anytime we see a prototype-less function that is variadic.  It
> seems rare enough not to warrant a separate warning option for it.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-21 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21 16:23 [C PATCH] Warn about variadic functions defined without prototypes (PR c/68024) Marek Polacek
2015-10-21 17:17 ` Joseph Myers

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).