OSDN Git Service

PR preprocessor/28709
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 12 Oct 2006 09:25:59 +0000 (09:25 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 12 Oct 2006 09:25:59 +0000 (09:25 +0000)
* macro.c (paste_tokens): Do error reporting here, use BUF with the
spelled LHS token as opposed to spelling it again.
(paste_all_tokens): Don't report errors here, just break on failure.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117664 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/paste14.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/macro.c

index 3de03fb..500edd2 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/28709
+       * gcc.dg/cpp/paste14.c: New test.
+
 2006-10-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/29175
diff --git a/gcc/testsuite/gcc.dg/cpp/paste14.c b/gcc/testsuite/gcc.dg/cpp/paste14.c
new file mode 100644 (file)
index 0000000..ec243c2
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR preprocessor/28709 */
+/* { dg-do preprocess } */
+
+#define foo - ## >>
+foo            /* { dg-error "pasting \"-\" and \">>\"" } */
+#define bar = ## ==
+bar            /* { dg-error "pasting \"=\" and \"==\"" } */
index 5871e95..ae87e0e 100644 (file)
@@ -1,3 +1,10 @@
+2006-10-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/28709
+       * macro.c (paste_tokens): Do error reporting here, use BUF with the
+       spelled LHS token as opposed to spelling it again.
+       (paste_all_tokens): Don't report errors here, just break on failure.
+
 2006-10-10  Brooks Moses  <bmoses@stanford.edu>
 
        * Makefile.in: Added empty "pdf" target.
index b29f3a0..be50c11 100644 (file)
@@ -430,15 +430,14 @@ stringify_arg (cpp_reader *pfile, macro_arg *arg)
 static bool
 paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
 {
-  unsigned char *buf, *end;
+  unsigned char *buf, *end, *lhsend;
   const cpp_token *lhs;
   unsigned int len;
-  bool valid;
 
   lhs = *plhs;
   len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
   buf = (unsigned char *) alloca (len);
-  end = cpp_spell_token (pfile, lhs, buf, false);
+  end = lhsend = cpp_spell_token (pfile, lhs, buf, false);
 
   /* Avoid comment headers, since they are still processed in stage 3.
      It is simpler to insert a space here, rather than modifying the
@@ -455,10 +454,22 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
   /* Set pfile->cur_token as required by _cpp_lex_direct.  */
   pfile->cur_token = _cpp_temp_token (pfile);
   *plhs = _cpp_lex_direct (pfile);
-  valid = pfile->buffer->cur == pfile->buffer->rlimit;
-  _cpp_pop_buffer (pfile);
+  if (pfile->buffer->cur != pfile->buffer->rlimit)
+    {
+      _cpp_pop_buffer (pfile);
+      _cpp_backup_tokens (pfile, 1);
+      *lhsend = '\0';
+
+      /* Mandatory error for all apart from assembler.  */
+      if (CPP_OPTION (pfile, lang) != CLK_ASM)
+       cpp_error (pfile, CPP_DL_ERROR,
+        "pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
+                  buf, cpp_token_as_text (pfile, rhs));
+      return false;
+    }
 
-  return valid;
+  _cpp_pop_buffer (pfile);
+  return true;
 }
 
 /* Handles an arbitrarily long sequence of ## operators, with initial
@@ -490,17 +501,7 @@ paste_all_tokens (cpp_reader *pfile, const cpp_token *lhs)
        abort ();
 
       if (!paste_tokens (pfile, &lhs, rhs))
-       {
-         _cpp_backup_tokens (pfile, 1);
-
-         /* Mandatory error for all apart from assembler.  */
-         if (CPP_OPTION (pfile, lang) != CLK_ASM)
-           cpp_error (pfile, CPP_DL_ERROR,
-        "pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
-                      cpp_token_as_text (pfile, lhs),
-                      cpp_token_as_text (pfile, rhs));
-         break;
-       }
+       break;
     }
   while (rhs->flags & PASTE_LEFT);