macro __VAR_ARGS_ bug??
Neil Booth
neil@daikokuya.co.uk
Mon Aug 5 13:55:00 GMT 2002
Zack Weinberg wrote:-
> This is the classic ambiguity between 'no arguments' and 'one
> argument, consisting of zero tokens'. I do not know what part of the
> mess that is vararg2.c is breaking; is it the same case? If so, we
> could just define this case to be 'no arguments' and be C99 compliant
> for the less ambiguous situation where the ellipsis isn't the only
> argument.
This patch does that. I'm a little unhappy that we're still not doing
the right thing for one case.
Do you think this is worth doing? If so, I'll create a testcase and
bootstrap / regtest it. This patch passes the CPP testsuite as is.
Neil.
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.120
diff -u -p -r1.120 cppmacro.c
--- cppmacro.c 2 Aug 2002 04:18:16 -0000 1.120
+++ cppmacro.c 5 Aug 2002 20:52:18 -0000
@@ -38,6 +38,10 @@ struct macro_arg
unsigned int expanded_count; /* # of tokens in expanded argument. */
};
+/* macro_arg->first is this if the variable arguments were omitted
+ entirely (i.e. not empty), as permitted by a GCC extension. */
+#define VOID_VARARGS NULL
+
/* Macro expansion. */
static int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
@@ -672,7 +676,11 @@ collect_args (pfile, node)
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
if (_cpp_arguments_ok (pfile, macro, node, argc))
- return base_buff;
+ {
+ if (macro->variadic && args[macro->paramc - 1].count == 0)
+ args[macro->paramc - 1].first = VOID_VARARGS;
+ return base_buff;
+ }
}
/* An error occurred. */
@@ -869,7 +877,7 @@ replace_args (pfile, node, macro, args)
&& macro->variadic
&& src->val.arg_no == macro->paramc)
{
- if (count == 0)
+ if (from == VOID_VARARGS)
dest--;
else
paste_flag = dest - 1;
More information about the Gcc-bugs
mailing list