[PATCH] preprocessor stringizing raw strings
authorNathan Sidwell <nathan@acm.org>
Tue, 10 Oct 2017 18:56:31 +0000 (18:56 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 10 Oct 2017 18:56:31 +0000 (18:56 +0000)
https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00611.html
libcpp/
PR preprocessor/82506
* macro.c (cpp_quote_string): Escape raw LFs.

gcc/testsuite/
PR preprocessor/82506
* g++.dg/cpp/string-3.C: New.

From-SVN: r253605

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp/string-3.C [new file with mode: 0644]
libcpp/ChangeLog
libcpp/macro.c

index c2e064c7ff7201857701e6b92264a43c4c4f1298..0cc5e32bdff4e4e589690f0986f7fff7a8ece9ae 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-10  Nathan Sidwell  <nathan@acm.org>
+
+       PR preprocessor/82506
+       * g++.dg/cpp/string-3.C: New.
+
 2017-10-10  Will Schmidt  <will_schmidt@vnet.ibm.com>
 
        * gcc.target/powerpc/fold-vec-splat-16.c: New
diff --git a/gcc/testsuite/g++.dg/cpp/string-3.C b/gcc/testsuite/g++.dg/cpp/string-3.C
new file mode 100644 (file)
index 0000000..92bd930
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/82506
+// { dg-do preprocess { target c++11 } }
+
+#define STRINGIZE(A) #A
+
+BEGIN STRINGIZE(R"(
+)") END
+
+// { dg-final { scan-file string-3.ii "BEGIN \"R\\\"(\\n)\\\"\"\n END" } }
index 0621074b53b6d1712aab4a843a911fc64c096907..f2c0d4d63fd897b85f4b307d7fc885e5bffbe81a 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-10  Nathan Sidwell  <nathan@acm.org>
+
+       PR preprocessor/82506
+       * macro.c (cpp_quote_string): Escape raw LFs.
+
 2017-09-15  Andrew Sutton  <andrew.n.sutton@gmail.com>
            Jakub Jelinek  <jakub@redhat.com>
 
index de18c2210cfc94d6e211efaa0ae8e8e524961a12..fab1cb051dc78569c3adf2661b22c043d8ed09c3 100644 (file)
@@ -502,13 +502,21 @@ cpp_quote_string (uchar *dest, const uchar *src, unsigned int len)
     {
       uchar c = *src++;
 
-      if (c == '\\' || c == '"')
+      switch (c)
        {
+       case '\n':
+         /* Naked LF can appear in raw string literals  */
+         c = 'n';
+         /* FALLTHROUGH */
+
+       case '\\':
+       case '"':
          *dest++ = '\\';
+         /* FALLTHROUGH */
+
+       default:
          *dest++ = c;
        }
-      else
-         *dest++ = c;
     }
 
   return dest;