From 35b82d26e5b92ba0471f59f0073590de3550f00a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 10 Oct 2017 18:56:31 +0000 Subject: [PATCH] [PATCH] preprocessor stringizing raw strings 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 | 5 +++++ gcc/testsuite/g++.dg/cpp/string-3.C | 9 +++++++++ libcpp/ChangeLog | 5 +++++ libcpp/macro.c | 14 +++++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp/string-3.C diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c2e064c7ff7..0cc5e32bdff 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-10 Nathan Sidwell + + PR preprocessor/82506 + * g++.dg/cpp/string-3.C: New. + 2017-10-10 Will Schmidt * 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 index 00000000000..92bd930dc26 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/string-3.C @@ -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" } } diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 0621074b53b..f2c0d4d63fd 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2017-10-10 Nathan Sidwell + + PR preprocessor/82506 + * macro.c (cpp_quote_string): Escape raw LFs. + 2017-09-15 Andrew Sutton Jakub Jelinek diff --git a/libcpp/macro.c b/libcpp/macro.c index de18c2210cf..fab1cb051dc 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -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; -- 2.30.2