Skip to content

Commit 7078a5c

Browse files
authored
Fix handling of escaped backslashes in expanded string (#464) (#481)
Original fix uses std::copy_if algorithm with overlapping input and output ranges - that behaviour is undefined. After reviewing it with @Maiqel and @lukasz-matysiak we have replace it with std::remove_if algorithm - which better describe what is happening and does not excercise undefined behaviour. From https://en.cppreference.com/w/cpp/algorithm/copy: > The behavior is undefined if d_first is within the range [first, last)
1 parent 9584fcc commit 7078a5c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

source/lex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ auto expand_string_literal(
429429
// Then put interpolated chunk into ret
430430
auto chunk = std::string{text.substr(open, pos - open)};
431431
{ // unescape chunk string
432-
auto last_it = std::copy_if(std::begin(chunk), std::end(chunk), std::begin(chunk), [escape = false](const auto& e) mutable {
432+
auto last_it = std::remove_if(std::begin(chunk), std::end(chunk), [escape = false](const auto& e) mutable {
433433
escape = !escape && e == '\\';
434-
return !escape;
434+
return escape;
435435
});
436436
chunk.erase(last_it, std::end(chunk));
437437
}

0 commit comments

Comments
 (0)