Hi! As can be seen on the testcases, before the -fdirectives-only preprocessing rewrite the preprocessor would assume // comments are terminated by the end of file even when newline wasn't there, but now we error out. The following patch restores the previous behavior.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-05-19 Jakub Jelinek <ja...@redhat.com> PR preprocessor/100646 * lex.c (cpp_directive_only_process): Treat end of file as termination for !is_block comments. * gcc.dg/cpp/pr100646-1.c: New test. * gcc.dg/cpp/pr100646-2.c: New test. --- libcpp/lex.c.jj 2021-05-12 15:13:57.000000000 +0200 +++ libcpp/lex.c 2021-05-18 19:48:04.211383565 +0200 @@ -4480,6 +4480,8 @@ cpp_directive_only_process (cpp_reader * break; } } + if (pos >= limit && !is_block) + goto done_comment; cpp_error_with_line (pfile, CPP_DL_ERROR, sloc, 0, "unterminated comment"); done_comment: --- gcc/testsuite/gcc.dg/cpp/pr100646-1.c.jj 2021-05-18 19:54:39.290077340 +0200 +++ gcc/testsuite/gcc.dg/cpp/pr100646-1.c 2021-05-18 19:55:16.139676735 +0200 @@ -0,0 +1,5 @@ +/* PR preprocessor/100646 */ +/* { dg-do compile } */ +/* { dg-options "-fdirectives-only -save-temps -std=c17" } */ +int main () { return 0; } +// Not newline terminated \ No newline at end of file --- gcc/testsuite/gcc.dg/cpp/pr100646-2.c.jj 2021-05-18 20:07:16.079360929 +0200 +++ gcc/testsuite/gcc.dg/cpp/pr100646-2.c 2021-05-18 20:09:56.545550245 +0200 @@ -0,0 +1,6 @@ +/* PR preprocessor/100646 */ +/* { dg-do compile } */ +/* { dg-options "-fdirectives-only -save-temps -std=c17" } */ +int main () { return 0; } +/* { dg-warning "backslash-newline at end of file" "" { target *-*-* } .+1 } */ +// Not newline terminated\ \ No newline at end of file Jakub