libcpp: Fix up raw string literal parsing error-recovery [PR96323]
authorJakub Jelinek <jakub@redhat.com>
Tue, 28 Jul 2020 13:40:15 +0000 (15:40 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 28 Jul 2020 13:40:15 +0000 (15:40 +0200)
For (invalid) newline inside of the raw string literal delimiter, doing
continue means we skip the needed processing of newlines.  Instead of
duplicating that, this patch just doesn't continue for those.

2020-07-28  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/96323
* lex.c (lex_raw_string): For c == '\n' don't continue after reporting
an prefix delimiter error.

* c-c++-common/cpp/pr96323.c: New test.

gcc/testsuite/c-c++-common/cpp/pr96323.c [new file with mode: 0644]
libcpp/lex.c

diff --git a/gcc/testsuite/c-c++-common/cpp/pr96323.c b/gcc/testsuite/c-c++-common/cpp/pr96323.c
new file mode 100644 (file)
index 0000000..7a8edff
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR preprocessor/96323 */
+/* { dg-do preprocess } */
+/* { dg-options "-std=gnu99 -Wno-c++-compat -trigraphs" { target c } } */
+/* { dg-options "-std=c++0x" { target c++ } } */
+/* { dg-error "invalid new-line in raw string delimiter" "" { target *-*-* } .+2 } */
+/* { dg-warning "missing terminating . character" "" { target *-*-* } .+2 } */
+const char tu[] = R"a";
+const char tua[] = "(R)a";
index 5d94882abe8a8f1827c800ab0ec05b26cae92d41..9aec9e0bd04e72a64a710a3fadb59e9c1913f66b 100644 (file)
@@ -1885,7 +1885,8 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
                 the best failure mode.  */
              prefix_len = 0;
            }
-         continue;
+         if (c != '\n')
+           continue;
        }
 
       if (phase != PHASE_NONE)