mirror of
https://github.com/nlohmann/json.git
synced 2026-09-29 11:10:30 +00:00
Fix CI: clang-tidy and clang/libstdc++ 10 in the MessagePack size tests (#5599)
The tests added by #5515 fail two ways on develop: - clang-tidy reports the size() overrides of huge_string and huge_binary (readability-convert-member-functions-to-static) and the non-const test value (misc-const-correctness); mark them like the #5584 types - clang with libstdc++ 10 cannot compile the file for C++17: the std::filesystem::path conversion considered for huge_string, a class derived from std::string, is ambiguous. Guard it with JSON_TEST_BEYOND_UINT32_STRING, which #5584 introduced for the same reason, and define that macro before both test blocks. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
+12
-11
@@ -2165,6 +2165,13 @@ TEST_CASE("MessagePack with std::byte")
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// the fake sizes below do not fit into a 32-bit std::size_t
|
// the fake sizes below do not fit into a 32-bit std::size_t
|
||||||
|
// 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
|
||||||
|
|
||||||
#if SIZE_MAX > UINT32_MAX
|
#if SIZE_MAX > UINT32_MAX
|
||||||
template<typename T, typename A = std::allocator<T>>
|
template<typename T, typename A = std::allocator<T>>
|
||||||
struct huge_array : std::vector<T, A>
|
struct huge_array : std::vector<T, A>
|
||||||
@@ -2262,11 +2269,12 @@ TEST_CASE("MessagePack Size above uint32 for object")
|
|||||||
object.fake_size = false;
|
object.fake_size = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef JSON_TEST_BEYOND_UINT32_STRING
|
||||||
struct huge_string : std::string
|
struct huge_string : std::string
|
||||||
{
|
{
|
||||||
using std::string::string;
|
using std::string::string;
|
||||||
|
|
||||||
std::size_t size() const noexcept
|
std::size_t size() const noexcept // NOLINT(readability-convert-member-functions-to-static)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(UINT32_MAX) + 1ULL;
|
return static_cast<std::size_t>(UINT32_MAX) + 1ULL;
|
||||||
}
|
}
|
||||||
@@ -2287,20 +2295,20 @@ using huge_string_json = nlohmann::basic_json <
|
|||||||
|
|
||||||
TEST_CASE("MessagePack Size above uint32 for string")
|
TEST_CASE("MessagePack Size above uint32 for string")
|
||||||
{
|
{
|
||||||
|
const huge_string_json j = "hello";
|
||||||
huge_string_json j = "hello";
|
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
huge_string_json::to_msgpack(j),
|
huge_string_json::to_msgpack(j),
|
||||||
"[json.exception.out_of_range.412] MessagePack length 4294967296 exceeds maximum of 4294967295",
|
"[json.exception.out_of_range.412] MessagePack length 4294967296 exceeds maximum of 4294967295",
|
||||||
json::out_of_range&);
|
json::out_of_range&);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct huge_binary : std::vector<std::uint8_t>
|
struct huge_binary : std::vector<std::uint8_t>
|
||||||
{
|
{
|
||||||
using std::vector<std::uint8_t>::vector;
|
using std::vector<std::uint8_t>::vector;
|
||||||
|
|
||||||
std::size_t size() const noexcept
|
std::size_t size() const noexcept // NOLINT(readability-convert-member-functions-to-static)
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(UINT32_MAX) + 1ULL;
|
return static_cast<std::size_t>(UINT32_MAX) + 1ULL;
|
||||||
}
|
}
|
||||||
@@ -2355,13 +2363,6 @@ class beyond_uint32_binary_t : public std::vector<std::uint8_t>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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
|
#ifdef JSON_TEST_BEYOND_UINT32_STRING
|
||||||
class beyond_uint32_string_t : public std::string
|
class beyond_uint32_string_t : public std::string
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user