]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: Fix up -fdirectives-only handling of // comments on last line not terminated...
authorJakub Jelinek <jakub@redhat.com>
Thu, 20 May 2021 07:09:07 +0000 (09:09 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 31 May 2021 11:54:04 +0000 (13:54 +0200)
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)

gcc/testsuite/gcc.dg/cpp/pr100646-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/pr100646-2.c [new file with mode: 0644]
libcpp/lex.c

diff --git a/gcc/testsuite/gcc.dg/cpp/pr100646-1.c b/gcc/testsuite/gcc.dg/cpp/pr100646-1.c
new file mode 100644 (file)
index 0000000..8f2caf4
--- /dev/null
@@ -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 (file)
index 0000000..a1deba1
--- /dev/null
@@ -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
index 6c0ca8d2e2db0d1a7c00dfbc160a3cff849fbffb..3791f388207bfe8a86e8f82b967b638fecc07f1a 100644 (file)
@@ -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;