Blob Blame History Raw
2000-09-04  Jakub Jelinek  <jakub@redhat.com>

	* cpplex.c (ON_REST_ARG): Check VAR_ARGS flag of current context,
	use posn - 1 to index into tokens array.
	(maybe_paste_with_next): Adjust caller.

	* gcc.dg/cpp/paste8.c: New test.

--- gcc/cpplex.c.jj	Fri Sep  1 10:13:33 2000
+++ gcc/cpplex.c	Fri Sep  1 13:37:01 2000
@@ -202,8 +202,8 @@ TOKEN_LEN (token)
 #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)
 #define ON_REST_ARG(c) \
  (((c)->flags & VAR_ARGS) \
-  && (c)->u.list->tokens[(c)->posn].val.aux \
-      == (unsigned int) ((c)->u.list->paramc - 1))
+  && ((c)-1)->u.list->tokens[((c)-1)->posn - 1].val.aux \
+      == (unsigned int) (((c)-1)->u.list->paramc - 1))
 
 #define ASSIGN_FLAGS_AND_POS(d, s) \
   do {(d)->flags = (s)->flags & (PREV_WHITE | BOL | PASTE_LEFT); \
@@ -2773,7 +2773,7 @@ maybe_paste_with_next (pfile, token)
 		     the special extended semantics (see above).  */
 		  if (token->type == CPP_COMMA
 		      && IS_ARG_CONTEXT (CURRENT_CONTEXT (pfile))
-		      && ON_REST_ARG (CURRENT_CONTEXT (pfile) - 1))
+		      && ON_REST_ARG (CURRENT_CONTEXT (pfile)))
 		    /* no warning */;
 		  else
 		    cpp_warning (pfile,
--- gcc/testsuite/gcc.dg/cpp/paste8.c.jj	Mon Sep  4 09:11:07 2000
+++ gcc/testsuite/gcc.dg/cpp/paste8.c	Mon Sep  4 09:28:28 2000
@@ -0,0 +1,15 @@
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+int foo(int, ...);
+
+#define a(x, y...) foo(x, ##y)
+a(1)
+a(1, 2, 3)
+#define b(x, y, z...) foo(x, ##y)
+b(1, 2, 3)				/* { dg-warning "pasting would not" } */
+#define c(x, y, z...) foo(x, ##z)
+c(1, 2)
+c(1, 2, 3)
+#define d(x) foo(##x)			/* { dg-warning "nothing can be pasted" } */
+d(1)