From d15a2d261b24adcbfe5e663b15dde3df5d2b3486 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 20 May 2021 09:09:07 +0200 Subject: libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [PR100646] 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. 2021-05-20 Jakub Jelinek 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libcpp') diff --git a/libcpp/lex.c b/libcpp/lex.c index 6fd722ab263..3618fa5d737 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4480,8 +4480,9 @@ cpp_directive_only_process (cpp_reader *pfile, break; } } - cpp_error_with_line (pfile, CPP_DL_ERROR, sloc, 0, - "unterminated comment"); + if (pos < limit || is_block) + cpp_error_with_line (pfile, CPP_DL_ERROR, sloc, 0, + "unterminated comment"); done_comment: lwm = pos; break; -- cgit v1.2.1