mirror of
https://github.com/nlohmann/json.git
synced 2026-09-24 06:10:22 +01:00
Fix two develop CI regressions: dump() nodiscard warning and binary-reader const-correctness (#5520)
* Discard dump()'s [[nodiscard]] return value in an exception-only check CHECK_THROWS_WITH_AS(j.dump(), ...) called dump() only to trigger and catch the exception, but never used the return value. dump() is warn_unused_result, so GCC's pedantic build (-Werror --all-warnings) rejected it as -Werror=unused-result, breaking ci_test_gcc. Wrapped in utils::ignore_return_value(), matching every other such call in this file. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Mark container_frame top as const in CBOR/UBJSON readers clang-tidy's misc-const-correctness flagged these on PR #5520's CI: the BSON sibling copy was already const, but these two were left mutable even though only container_stack.back().remaining is ever written. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1434,7 +1434,7 @@ class binary_reader
|
|||||||
// a copy, not a reference: it must stay valid across the
|
// a copy, not a reference: it must stay valid across the
|
||||||
// pop_back() below, which destroys the container_stack element
|
// pop_back() below, which destroys the container_stack element
|
||||||
// it would otherwise alias
|
// it would otherwise alias
|
||||||
container_frame top = container_stack.back();
|
const container_frame top = container_stack.back();
|
||||||
bool at_end = false;
|
bool at_end = false;
|
||||||
|
|
||||||
if (top.remaining != npos)
|
if (top.remaining != npos)
|
||||||
@@ -2211,7 +2211,7 @@ class binary_reader
|
|||||||
// would otherwise alias.
|
// would otherwise alias.
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
container_frame top = container_stack.back();
|
const container_frame top = container_stack.back();
|
||||||
|
|
||||||
if (top.remaining != npos)
|
if (top.remaining != npos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13383,7 +13383,7 @@ class binary_reader
|
|||||||
// a copy, not a reference: it must stay valid across the
|
// a copy, not a reference: it must stay valid across the
|
||||||
// pop_back() below, which destroys the container_stack element
|
// pop_back() below, which destroys the container_stack element
|
||||||
// it would otherwise alias
|
// it would otherwise alias
|
||||||
container_frame top = container_stack.back();
|
const container_frame top = container_stack.back();
|
||||||
bool at_end = false;
|
bool at_end = false;
|
||||||
|
|
||||||
if (top.remaining != npos)
|
if (top.remaining != npos)
|
||||||
@@ -14160,7 +14160,7 @@ class binary_reader
|
|||||||
// would otherwise alias.
|
// would otherwise alias.
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
container_frame top = container_stack.back();
|
const container_frame top = container_stack.back();
|
||||||
|
|
||||||
if (top.remaining != npos)
|
if (top.remaining != npos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ TEST_CASE("serialization of strings (bulk fast path)")
|
|||||||
SECTION("invalid UTF-8 handling is unaffected by the fast path")
|
SECTION("invalid UTF-8 handling is unaffected by the fast path")
|
||||||
{
|
{
|
||||||
const json j = std::string("valid\xff" "more");
|
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, ' ', 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, ' ', true, json::error_handler_t::replace) == "\"valid\\ufffdmore\"");
|
||||||
CHECK(j.dump(-1, ' ', false, json::error_handler_t::ignore) == "\"validmore\"");
|
CHECK(j.dump(-1, ' ', false, json::error_handler_t::ignore) == "\"validmore\"");
|
||||||
|
|||||||
Reference in New Issue
Block a user