cpptrad.c (_cpp_scan_out_logical_line): Improve test for whether directive begins...
authorNathanael Nerode <neroden@gcc.gnu.org>
Wed, 19 Nov 2003 18:48:53 +0000 (18:48 +0000)
committerNathanael Nerode <neroden@gcc.gnu.org>
Wed, 19 Nov 2003 18:48:53 +0000 (18:48 +0000)
* cpptrad.c (_cpp_scan_out_logical_line): Improve test for
whether directive begins at the beginning of a line.

(testsuite)
* gcc.dg/cpp/trad/xwin1.c: New test case.

From-SVN: r73740

gcc/ChangeLog
gcc/cpptrad.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/trad/xwin1.c [new file with mode: 0644]

index 932a06b5439c8f2a3f9342cdd7e4ed199f95cfc8..0b4e2872d91d2864feabcc92b10a79673e04b60d 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-19  Nathanael Nerode  <neroden@gcc.gnu.org>
+
+       * cpptrad.c (_cpp_scan_out_logical_line): Improve test for
+       whether directive begins at the beginning of a line.
+
 2003-11-19  Richard Sandiford  <rsandifo@redhat.com>
 
        * config/frv/frv.c (frv_init_libfuncs): Correct ufix_optab entries.
index 0f98a8ad3dda8e655f00c9586ca076787406a226..6da19cc41ec980e4ac9c61188b2e8374ed09c6ba 100644 (file)
@@ -350,6 +350,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
   unsigned int c, paren_depth = 0, quote;
   enum ls lex_state = ls_none;
   bool header_ok;
+  const uchar *start_of_input_line;
 
   fmacro.buff = NULL;
 
@@ -359,6 +360,9 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
   RLIMIT (pfile->context) = pfile->buffer->rlimit;
   pfile->out.cur = pfile->out.base;
   pfile->out.first_line = pfile->line;
+  /* start_of_input_line is needed to make sure that directives really,
+     really start at the first character of the line. */
+  start_of_input_line = pfile->buffer->cur;
  new_context:
   context = pfile->context;
   cur = CUR (context);
@@ -581,7 +585,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
          break;
 
        case '#':
-         if (out - 1 == pfile->out.base
+         if (cur - 1 == start_of_input_line
              /* A '#' from a macro doesn't start a directive.  */
              && !pfile->context->prev
              && !pfile->state.in_directive)
index 0f66268f1023bbe7ad4911821ecf3efe9b6fd86a..fdfcc6ebdcb81269616d90c19935e138ac195a07 100644 (file)
@@ -1,3 +1,7 @@
+2003-11-19  Nathanael Nerode  <neroden@gcc.gnu.org>
+
+       * gcc.dg/cpp/trad/xwin1.c: New test case.
+
 2003-11-19  Andreas Tobler  <a.tobler@schweiz.ch>
 
        * g++.dg/compat/compat.exp: Add DYLD_LIBRARY_PATH for darwin.
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/xwin1.c b/gcc/testsuite/gcc.dg/cpp/trad/xwin1.c
new file mode 100644 (file)
index 0000000..21220d1
--- /dev/null
@@ -0,0 +1,13 @@
+/* XWindows (as of 4.3) does some pretty strange things with cpp.
+   This tests one of them; the leading comments are supposed to be
+   eaten by the preprocessor; but the 'directives' after them are
+   supposed to be retained as text, not processed, so that imake's cpp
+   can be run on the output!
+   { dg-do preprocess }
+*/
+
+/**/#if 0
+passed
+/**/#endif
+
+/* { dg-final { scan-file xwin1.i "(^|\n)#if 0" } } */