re PR c/68024 (Diagnose variadic functions defined without prototypes)
authorMarek Polacek <polacek@redhat.com>
Wed, 21 Oct 2015 17:30:20 +0000 (17:30 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 21 Oct 2015 17:30:20 +0000 (17:30 +0000)
PR c/68024
* c-decl.c (start_function): Warn about vararg functions without
a prototype.

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

From-SVN: r229131

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr68024.c [new file with mode: 0644]

index 34aafc2c59d92a6a72d3c0a74b905bf91ee84ef5..b5179a3a714731fb33c61aec8a6f999ab16a15e1 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c/68024
+       * c-decl.c (start_function): Warn about vararg functions without
+       a prototype.
+
 2015-10-21  Ilya Enkovich  <enkovich.gnu@gmail.com>
 
        * c-typeck.c (build_conditional_expr): Use boolean vector
index ce8406a13e47070579a5cc6ac3925ccad689cb96..4a0e090dbd07df4baa16ab276d19fbdea4777cfa 100644 (file)
@@ -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);
index db0f89665a29c0ed8cd0c730e58508ec8c3d956e..4f10616178a8b97fe2ab99d0e7bb334996543e9f 100644 (file)
@@ -1,3 +1,8 @@
+2015-10-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c/68024
+       * gcc.dg/pr68024.c: New test.
+
 2015-10-21  Nathan Sidwell  <nathan@codesourcery.com>
 
        * c-c++-common/goacc/clauses-fail.c: Adjust errors.
diff --git a/gcc/testsuite/gcc.dg/pr68024.c b/gcc/testsuite/gcc.dg/pr68024.c
new file mode 100644 (file)
index 0000000..a750917
--- /dev/null
@@ -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" } */