diff options
author | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-10-10 18:56:31 +0000 |
---|---|---|
committer | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-10-10 18:56:31 +0000 |
commit | de382e64c207f9c471d765cb426145618e94054a (patch) | |
tree | 4fc1cc6080449593ca09e8bd58284591bc52f03a /libcpp | |
parent | 5ef60a2835241e1b41905bbab820f1a65b8fd05b (diff) |
[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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253605 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 5 | ||||
-rw-r--r-- | libcpp/macro.c | 14 |
2 files changed, 16 insertions, 3 deletions
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 <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> 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; |