This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: macro __VAR_ARGS_ bug??


Neil Booth wrote:-

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

Sorry, I screwed up.  This is the patch that does what you said, but
keeps the comma if the macro has a non-varargs argument.  It passes
the test suite, and behaves as expected with Reza's case.

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 21:05:40 -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,12 @@ 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
+	      && (argc < macro->paramc || (argc == 1 && args[0].count == 0)))
+	    args[macro->paramc - 1].first = VOID_VARARGS;
+	  return base_buff;
+	}
     }
 
   /* An error occurred.  */
@@ -869,7 +878,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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]