From 67bb400b3c4540fec21cf07ee1536ba3d55012ee Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 26 Sep 2026 10:46:17 +0200 Subject: [PATCH] Skip the MessagePack string length test for clang with libstdc++ 10 C++17 builds consider the std::filesystem::path conversion for the string type, and with clang and libstdc++ 10 that conversion is ambiguous for a class derived from std::string. Creating the value from its type did not avoid it, since any basic_json with that string type instantiates the check. The binary and ext cases are still tested there. Signed-off-by: Niels Lohmann --- tests/src/unit-msgpack.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 0c0aee8bc..21a21f3ca 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -2173,6 +2173,14 @@ class beyond_uint32_binary_t : public std::vector } }; +// with clang and libstdc++ 10, the std::filesystem::path conversion that +// C++17 builds consider for every string type is ambiguous for a class +// derived from std::string, so the string case is not tested there +#if !(defined(__clang__) && defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11) + #define JSON_TEST_BEYOND_UINT32_STRING 1 +#endif + +#ifdef JSON_TEST_BEYOND_UINT32_STRING class beyond_uint32_string_t : public std::string { public: @@ -2183,14 +2191,17 @@ class beyond_uint32_string_t : public std::string return beyond_uint32_size(); } }; +#endif using beyond_uint32_binary_json = nlohmann::basic_json < std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, nlohmann::adl_serializer, beyond_uint32_binary_t, void >; +#ifdef JSON_TEST_BEYOND_UINT32_STRING using beyond_uint32_string_json = nlohmann::basic_json < std::map, std::vector, beyond_uint32_string_t, bool, std::int64_t, std::uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector, void >; +#endif } // namespace TEST_CASE("MessagePack lengths beyond UINT32_MAX cannot be serialized") @@ -2208,11 +2219,13 @@ 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&); +#ifdef JSON_TEST_BEYOND_UINT32_STRING // 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 } #endif }