Skip to content

Commit dc7e10c

Browse files
committed
Leave \ escapes in char literals in string interpolations
Closes #861 But " must still be escaped as \" inside a string interpolation expression. Removing that one need to escape inside a string interpolation would likely require switching to prefix $ -- see the #861 comment thread
1 parent 759c3b3 commit dc7e10c

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.3.0 Build 8C17:1632
2+
cppfront compiler v0.3.0 Build 8C18:0609
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8C17:1632"
1+
"8C18:0609"

source/lex.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,16 @@ auto expand_string_literal(
427427

428428
// Then put interpolated chunk into ret
429429
auto chunk = std::string{text.substr(open, pos - open)};
430-
{ // unescape chunk string
431-
auto last_it = std::remove_if(std::begin(chunk), std::end(chunk), [escape = false](const auto& e) mutable {
432-
escape = !escape && e == '\\';
433-
return escape;
434-
});
430+
{ // unescape chunk string
431+
auto last_it = std::remove_if(
432+
std::begin(chunk),
433+
std::end(chunk),
434+
[escape = false, prev = ' '](const auto& e) mutable {
435+
escape = !escape && prev != '\'' && e == '\\';
436+
prev = e;
437+
return escape;
438+
}
439+
);
435440
chunk.erase(last_it, std::end(chunk));
436441
}
437442

0 commit comments

Comments
 (0)