Patchwork Support DEC-C extensions

login
register
mail settings
Submitter Tristan Gingold
Date Oct. 7, 2011, 9:44 a.m.
Message ID <86BF0CA4-502F-4C53-8658-4666CF3F2C14@adacore.com>
Download mbox | patch
Permalink /patch/118288/
State New
Headers show

Comments

Tristan Gingold - Oct. 7, 2011, 9:44 a.m.
On Oct 6, 2011, at 4:12 PM, Joseph S. Myers wrote:

> On Thu, 6 Oct 2011, Tristan Gingold wrote:
> 
>> So the consensus is for a dedicated option.  Which one do you prefer ?
>> 
>> -funnamed-variadic-parameter
>> -fpointless-variadic-functions
>> -fallow-parameterless-variadic-functions
> 
> I prefer -fallow-parameterless-variadic-functions.

Here is my patch with the option renamed.

Ok for trunk ?

Bootstrapped on x86_64/Darwin, va-arg retested.

Tristan.

2011-09-29  Tristan Gingold  <gingold@adacore.com>

        * doc/invoke.texi: Document -fallow-parameterless-variadic-functions.
        * c-parser.c (c_parser_parms_list_declarator): Handle it.

gcc/c-family/ChangeLog
2011-09-29  Tristan Gingold  <gingold@adacore.com>

        * c.opt (fallow-parameterless-variadic-functions): New.

gcc/testsuite/ChangeLog
2011-09-29  Tristan Gingold  <gingold@adacore.com>

        * gcc.dg/va-arg-4.c: New test.
        * gcc.dg/va-arg-5.c: Ditto.
Joseph S. Myers - Oct. 7, 2011, 3:04 p.m.
On Fri, 7 Oct 2011, Tristan Gingold wrote:

> Here is my patch with the option renamed.
> 
> Ok for trunk ?

OK with a spelling fix:

> +@item -fallow-parameterless-variadic-functions
> +Accept variadic functions without named parameters.
> +
> +Although it is possible to define such a function, this is not very
> +usefull as it is not possible to read the arguments.  This is only

"useful"

Patch

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index e6ac5dc..79287c4 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -700,6 +700,10 @@  Enforce class member access control semantics
 fall-virtual
 C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
 
+fallow-parameterless-variadic-functions
+C ObjC Var(flag_allow_parameterless_variadic_functions)
+Allow variadic functions without named parameter
+
 falt-external-templates
 C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
 No longer supported
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index ff376df..0ca0f04 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -3159,10 +3159,19 @@  c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr)
   if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
     {
       struct c_arg_info *ret = build_arg_info ();
-      /* Suppress -Wold-style-definition for this case.  */
-      ret->types = error_mark_node;
-      error_at (c_parser_peek_token (parser)->location,
-		"ISO C requires a named argument before %<...%>");
+
+      if (flag_allow_parameterless_variadic_functions)
+        {
+          /* F (...) is allowed.  */
+          ret->types = NULL_TREE;
+        }
+      else
+        {
+          /* Suppress -Wold-style-definition for this case.  */
+          ret->types = error_mark_node;
+          error_at (c_parser_peek_token (parser)->location,
+                    "ISO C requires a named argument before %<...%>");
+        }
       c_parser_consume_token (parser);
       if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
 	{
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e166964..d42af1d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -170,7 +170,7 @@  in the following sections.
 @item C Language Options
 @xref{C Dialect Options,,Options Controlling C Dialect}.
 @gccoptlist{-ansi  -std=@var{standard}  -fgnu89-inline @gol
--aux-info @var{filename} @gol
+-aux-info @var{filename} -fallow-parameterless-variadic-functions @gol
 -fno-asm  -fno-builtin  -fno-builtin-@var{function} @gol
 -fhosted  -ffreestanding -fopenmp -fms-extensions -fplan9-extensions @gol
 -trigraphs  -no-integrated-cpp  -traditional  -traditional-cpp @gol
@@ -1618,6 +1618,13 @@  character).  In the case of function definitions, a K&R-style list of
 arguments followed by their declarations is also provided, inside
 comments, after the declaration.
 
+@item -fallow-parameterless-variadic-functions
+Accept variadic functions without named parameters.
+
+Although it is possible to define such a function, this is not very
+usefull as it is not possible to read the arguments.  This is only
+supported for C as this construct is allowed by C++.
+
 @item -fno-asm
 @opindex fno-asm
 Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
diff --git a/gcc/testsuite/gcc.dg/va-arg-4.c b/gcc/testsuite/gcc.dg/va-arg-4.c
new file mode 100644
index 0000000..6d737c4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/va-arg-4.c
@@ -0,0 +1,3 @@ 
+/* { dg-do compile } */
+#include <stdarg.h>
+extern void baz(...);	/* { dg-error "requires a named argument" } */
diff --git a/gcc/testsuite/gcc.dg/va-arg-5.c b/gcc/testsuite/gcc.dg/va-arg-5.c
new file mode 100644
index 0000000..a00616e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/va-arg-5.c
@@ -0,0 +1,4 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fallow-parameterless-variadic-functions" } */
+#include <stdarg.h>
+extern void baz(...);