From 0349745c4d3e7da8fc47ed6eb7a8f832065782e8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 6 Sep 2026 11:22:27 +0200 Subject: [PATCH] Fix MSVC source-encoding portability in the wide-string position test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use é escapes instead of a literal UTF-8-encoded 'é' inside the L"" literal, so the wide string's content does not depend on the compiler's assumed source character set (MSVC without /utf-8 decodes raw non-ASCII source bytes using the system code page rather than as UTF-8, which was producing a wstring of unexpected length/content and failing the ws.size()/end_pos() assertions on Windows CI). Also reworded a comment that unintentionally embedded the literal substring "TODO check", which clang-tidy's google-readability-todo check flags regardless of quoting context. Signed-off-by: Niels Lohmann --- tests/src/unit-class_parser.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index ef4b1c165..e36089bd9 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -2195,9 +2195,10 @@ TEST_CASE("diagnostic positions: value lifetime, input adapters, and SAX") { // basic_json(basic_json&&) (json.hpp, around line 1265) copies // other's start_position/end_position into *this and then resets - // other's to npos (see the "// cppcheck-suppress[accessForwarded] - // TODO check" comments there). Only the top-level moved-from value - // is affected; its (moved-away) children are gone along with it. + // other's to npos (see the cppcheck-suppress[accessForwarded] + // annotation there, which flags this reset as worth a second + // look). Only the top-level moved-from value is affected; its + // (moved-away) children are gone along with it. const std::string s = R"({"a":1,"b":[1,2,3]})"; json a = json::parse(s); const auto a_start = a.start_pos(); @@ -2346,7 +2347,12 @@ TEST_CASE("diagnostic positions: value lifetime, input adapters, and SAX") // transcoded UTF-8 byte stream, so reported positions are byte // offsets into that UTF-8 stream, not indices into the original // std::wstring. - const std::wstring ws = L"{\"a\":\"éé\"}"; + // é (rather than a literal 'é' byte sequence in this source + // file) so the wide-string literal's meaning does not depend on + // the compiler's assumed source character set (MSVC, without + // /utf-8, would otherwise decode the raw UTF-8 bytes using the + // system code page instead of as UTF-8) + const std::wstring ws = L"{\"a\":\"\u00e9\u00e9\"}"; CHECK(ws.size() == 10); // 10 wide characters const json j = json::parse(ws);