This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Warn about variadic main (PR c/60156)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 12 Feb 2014 10:51:32 +0100
- Subject: [C PATCH] Warn about variadic main (PR c/60156)
- Authentication-results: sourceware.org; auth=none
I figured it might be a good idea to warn about variadic main decl
(well, not in freestanding environment where it's
implementation-defined).
Regtested/bootstrapped on x86_64-linux, ok for 5.0?
2014-02-12 Marek Polacek <polacek@redhat.com>
PR c/60156
c-family/
* c-common.c (check_main_parameter_types): Warn about variadic main.
testsuite/
* c-c++-common/pr60156.c: New test.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 5cf285b..bdf2852 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -2228,6 +2228,10 @@ check_main_parameter_types (tree decl)
if (argct > 0 && (argct < 2 || argct > 3))
pedwarn (input_location, OPT_Wmain,
"%q+D takes only zero or two arguments", decl);
+
+ if (stdarg_p (TREE_TYPE (decl)))
+ pedwarn (input_location, OPT_Wmain,
+ "%q+D declared as variadic function", decl);
}
/* vector_targets_convertible_p is used for vector pointer types. The
diff --git gcc/testsuite/c-c++-common/pr60156.c gcc/testsuite/c-c++-common/pr60156.c
index e69de29..1e8204c 100644
--- gcc/testsuite/c-c++-common/pr60156.c
+++ gcc/testsuite/c-c++-common/pr60156.c
@@ -0,0 +1,9 @@
+/* PR c/60156 */
+/* { dg-do compile } */
+/* { dg-options "-Wpedantic" } */
+
+int
+main (int argc, char *argv[], ...) /* { dg-warning "declared as variadic function" } */
+{
+ return 0;
+}
Marek