public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-8490] libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [P
@ 2021-05-31 14:08 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-05-31 14:08 UTC (permalink / raw)
To: gcc-cvs
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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-31 14:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31 14:08 [gcc r11-8490] libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated with newline [P Jakub Jelinek
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).