diff --git a/docs/mkdocs/docs/api/basic_json/to_msgpack.md b/docs/mkdocs/docs/api/basic_json/to_msgpack.md index 0330461ea..b3bcaab7f 100644 --- a/docs/mkdocs/docs/api/basic_json/to_msgpack.md +++ b/docs/mkdocs/docs/api/basic_json/to_msgpack.md @@ -30,6 +30,10 @@ The exact mapping and its limitations are described on a [dedicated page](../../ 1. MessagePack serialization as a byte vector 2. (none) +## Exception safety + +Strong guarantee: if an exception is thrown, there are no changes in the JSON value. + ## Exceptions - Throws [`out_of_range.412`](../../home/exceptions.md#jsonexceptionout_of_range412) if the length of a string, binary @@ -39,10 +43,6 @@ The exact mapping and its limitations are described on a [dedicated page](../../ exceeds 255, the maximum of the MessagePack ext type; example: `"subtype 70000 is too large for the MessagePack ext type (max 255)"` -## Exception safety - -Strong guarantee: if an exception is thrown, there are no changes in the JSON value. - ## Complexity Linear in the size of the JSON value `j`. diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 9d2ed55d7..a874855fe 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -479,6 +479,7 @@ class binary_writer JSON_THROW(out_of_range::create(412, concat("MessagePack length ", std::to_string(length), " exceeds maximum of ", std::to_string((std::numeric_limits::max)())), &j)); } + static_cast(j); return static_cast(length); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cd523127e..2ab9fb027 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19944,6 +19944,7 @@ class binary_writer JSON_THROW(out_of_range::create(412, concat("MessagePack length ", std::to_string(length), " exceeds maximum of ", std::to_string((std::numeric_limits::max)())), &j)); } + static_cast(j); return static_cast(length); } diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index c1693065b..0c0aee8bc 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -2208,7 +2208,10 @@ TEST_CASE("MessagePack lengths beyond UINT32_MAX cannot be serialized") const beyond_uint32_binary_json ext = beyond_uint32_binary_json::binary(beyond_uint32_binary_t{}, 42); CHECK_THROWS_WITH_AS(beyond_uint32_binary_json::to_msgpack(ext), expected, beyond_uint32_binary_json::out_of_range&); - const beyond_uint32_string_json string = beyond_uint32_string_t("value"); + // created from its type rather than from a beyond_uint32_string_t: + // that would consider the std::filesystem::path conversion, which + // libstdc++ 10 cannot decide for a class derived from std::string + const beyond_uint32_string_json string(beyond_uint32_string_json::value_t::string); CHECK_THROWS_WITH_AS(beyond_uint32_string_json::to_msgpack(string), expected, beyond_uint32_string_json::out_of_range&); } #endif