public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8490] libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [P Date: Mon, 31 May 2021 14:08:44 +0000 (GMT) [thread overview] Message-ID: <20210531140844.2FA483848010@sourceware.org> (raw) https://gcc.gnu.org/g:3a2fa2e819d4714cecf5048eda2b7e52ba9e3cdd commit r11-8490-g3a2fa2e819d4714cecf5048eda2b7e52ba9e3cdd Author: Jakub Jelinek <jakub@redhat.com> Date: Thu May 20 09:09:07 2021 +0200 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 <jakub@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. (cherry picked from commit d15a2d261b24adcbfe5e663b15dde3df5d2b3486) Diff: --- gcc/testsuite/gcc.dg/cpp/pr100646-1.c | 5 +++++ gcc/testsuite/gcc.dg/cpp/pr100646-2.c | 6 ++++++ libcpp/lex.c | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/cpp/pr100646-1.c b/gcc/testsuite/gcc.dg/cpp/pr100646-1.c new file mode 100644 index 00000000000..8f2caf40c3f --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100646-1.c @@ -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 diff --git a/gcc/testsuite/gcc.dg/cpp/pr100646-2.c b/gcc/testsuite/gcc.dg/cpp/pr100646-2.c new file mode 100644 index 00000000000..a1deba10634 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr100646-2.c @@ -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 diff --git a/libcpp/lex.c b/libcpp/lex.c index 6c0ca8d2e2d..3791f388207 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -4469,8 +4469,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;
reply other threads:[~2021-05-31 14:08 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210531140844.2FA483848010@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).