From dc7e10cdcc7ad6129414ca0e598dfb9f7f554827 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Mon, 18 Dec 2023 06:39:04 -1000 Subject: [PATCH] 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 --- regression-tests/test-results/version | 2 +- source/build.info | 2 +- source/lex.h | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/regression-tests/test-results/version b/regression-tests/test-results/version index 83f6b98821..905d9120c9 100644 --- a/regression-tests/test-results/version +++ b/regression-tests/test-results/version @@ -1,5 +1,5 @@ -cppfront compiler v0.3.0 Build 8C17:1632 +cppfront compiler v0.3.0 Build 8C18:0609 Copyright(c) Herb Sutter All rights reserved SPDX-License-Identifier: CC-BY-NC-ND-4.0 diff --git a/source/build.info b/source/build.info index 9e75a0fb37..474b47ca44 100644 --- a/source/build.info +++ b/source/build.info @@ -1 +1 @@ -"8C17:1632" \ No newline at end of file +"8C18:0609" \ No newline at end of file diff --git a/source/lex.h b/source/lex.h index 5e8605d277..b320ae3906 100644 --- a/source/lex.h +++ b/source/lex.h @@ -427,11 +427,16 @@ auto expand_string_literal( // Then put interpolated chunk into ret auto chunk = std::string{text.substr(open, pos - open)}; - { // unescape chunk string - auto last_it = std::remove_if(std::begin(chunk), std::end(chunk), [escape = false](const auto& e) mutable { - escape = !escape && e == '\\'; - return escape; - }); + { // unescape chunk string + auto last_it = std::remove_if( + std::begin(chunk), + std::end(chunk), + [escape = false, prev = ' '](const auto& e) mutable { + escape = !escape && prev != '\'' && e == '\\'; + prev = e; + return escape; + } + ); chunk.erase(last_it, std::end(chunk)); }