diff --git a/gcc/testsuite/gcc.dg/cpp/pr100392.c b/gcc/testsuite/gcc.dg/cpp/pr100392.c new file mode 100644 index 00000000000..670ad2b742c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100392.c @@ -0,0 +1,5 @@ +/* PR preprocessor/100392 */ +/* { dg-do compile } */ +/* { dg-options "-save-temps -fdirectives-only" } */ + +#include "pr100392.h" diff --git a/gcc/testsuite/gcc.dg/cpp/pr100392.h b/gcc/testsuite/gcc.dg/cpp/pr100392.h new file mode 100644 index 00000000000..340bc92cd56 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100392.h @@ -0,0 +1,4 @@ +/* PR preprocessor/100392 */ + +/* No newline after ; below. */ +int i = 1; \ No newline at end of file diff --git a/libcpp/lex.c b/libcpp/lex.c index 36cd2e30630..6fd722ab263 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4768,7 +4768,18 @@ cpp_directive_only_process (cpp_reader *pfile, } if (buffer->rlimit > base && !pfile->state.skipping) - cb (pfile, CPP_DO_print, data, line_count, base, buffer->rlimit - base); + { + const unsigned char *limit = buffer->rlimit; + /* If the file was not newline terminated, add rlimit, which is + guaranteed to point to a newline, to the end of our range. */ + if (limit[-1] != '\n') + { + limit++; + CPP_INCREMENT_LINE (pfile, 0); + line_count++; + } + cb (pfile, CPP_DO_print, data, line_count, base, limit - base); + } _cpp_pop_buffer (pfile); }