This patch fixes PR 82506, where we fail to properly stringize a raw
string literal, which can contain a raw LF character.
When we're not just preprocessing, there isn't a problem. The string
literal gets correctly escaped into the assembly file. This is just a
problem with preprocessing.
Applying to trunk.
nathan
--
Nathan Sidwell
2017-10-10 Nathan Sidwell <nat...@acm.org>
libcpp/
PR preprocessor/82506
* macro.c (cpp_quote_string): Escape raw LFs.
gcc/testsuite/
PR preprocessor/82506
* g++.dg/cpp/string-3.C: New.
Index: gcc/testsuite/g++.dg/cpp/string-3.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/string-3.C (revision 0)
+++ gcc/testsuite/g++.dg/cpp/string-3.C (working copy)
@@ -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: libcpp/macro.c
===================================================================
--- libcpp/macro.c (revision 253587)
+++ libcpp/macro.c (working copy)
@@ -502,13 +502,21 @@ cpp_quote_string (uchar *dest, const uch
{
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;