diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index efa93070d..e0343fd0b 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -1434,7 +1434,7 @@ class binary_reader // a copy, not a reference: it must stay valid across the // pop_back() below, which destroys the container_stack element // it would otherwise alias - container_frame top = container_stack.back(); + const container_frame top = container_stack.back(); bool at_end = false; if (top.remaining != npos) @@ -2211,7 +2211,7 @@ class binary_reader // would otherwise alias. for (;;) { - container_frame top = container_stack.back(); + const container_frame top = container_stack.back(); if (top.remaining != npos) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 150118a1c..3b2233a57 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13383,7 +13383,7 @@ class binary_reader // a copy, not a reference: it must stay valid across the // pop_back() below, which destroys the container_stack element // it would otherwise alias - container_frame top = container_stack.back(); + const container_frame top = container_stack.back(); bool at_end = false; if (top.remaining != npos) @@ -14160,7 +14160,7 @@ class binary_reader // would otherwise alias. for (;;) { - container_frame top = container_stack.back(); + const container_frame top = container_stack.back(); if (top.remaining != npos) { diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index eddf59f2c..511108c64 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp @@ -469,7 +469,7 @@ TEST_CASE("serialization of strings (bulk fast path)") SECTION("invalid UTF-8 handling is unaffected by the fast path") { const json j = std::string("valid\xff" "more"); - CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 5: 0xFF", json::type_error&); + CHECK_THROWS_WITH_AS(utils::ignore_return_value(j.dump()), "[json.exception.type_error.316] invalid UTF-8 byte at index 5: 0xFF", json::type_error&); CHECK(j.dump(-1, ' ', false, json::error_handler_t::replace) == "\"valid\xef\xbf\xbd" "more\""); CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"valid\\ufffdmore\""); CHECK(j.dump(-1, ' ', false, json::error_handler_t::ignore) == "\"validmore\"");