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  <pola...@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

Reply via email to