diff --git a/gcc/testsuite/gcc.dg/cpp/pr98882.c b/gcc/testsuite/gcc.dg/cpp/pr98882.c new file mode 100644 index 00000000000..e831df09d0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr98882.c @@ -0,0 +1,6 @@ +/* PR preprocessor/98882 */ +/* { dg-do preprocess } */ +/* { dg-options "-fdirectives-only" } */ + +/* Last line does not end with a newline. */ + /*Here*/ \ No newline at end of file diff --git a/libcpp/lex.c b/libcpp/lex.c index 6af140459ad..06bcc31c87e 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4318,9 +4318,9 @@ cpp_directive_only_process (cpp_reader *pfile, buffer->cur_note = buffer->notes_used = 0; buffer->cur = buffer->line_base = buffer->next_line; buffer->need_line = false; - /* Files always end in a newline. We rely on this for + /* Files always end in a newline or carriage return. We rely on this for character peeking safety. */ - gcc_assert (buffer->rlimit[-1] == '\n'); + gcc_assert (buffer->rlimit[0] == '\n' || buffer->rlimit[0] == '\r'); const unsigned char *base = buffer->cur; unsigned line_count = 0;