diff --git a/tests/src/unit-json_view.cpp b/tests/src/unit-json_view.cpp index de902bde7..ee7a8da57 100644 --- a/tests/src/unit-json_view.cpp +++ b/tests/src/unit-json_view.cpp @@ -105,6 +105,20 @@ template struct failing_allocator { using value_type = T; + // GCC 4.8's std::map takes these from the allocator instead of from + // std::allocator_traits + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; + + template + struct rebind + { + using other = failing_allocator; + }; failing_allocator() = default; @@ -118,6 +132,26 @@ struct failing_allocator void deallocate(T* /*p*/, std::size_t /*n*/) noexcept {} // NOLINT(readability-convert-member-functions-to-static) + // GCC 4.8's std::map calls these on the allocator directly instead of + // going through std::allocator_traits + std::size_t max_size() const noexcept // NOLINT(readability-convert-member-functions-to-static) + { + return (std::numeric_limits::max)() / sizeof(T); + } + + template + void construct(U* p, Args&& ... args) // NOLINT(readability-convert-member-functions-to-static) + { + ::new (static_cast(p)) U(std::forward(args)...); + } + + template + void destroy(U* p) noexcept // NOLINT(readability-convert-member-functions-to-static) + { + static_cast(p); // unused for trivially destructible types + p->~U(); + } + template bool operator==(const failing_allocator& /*other*/) const noexcept { @@ -270,7 +304,7 @@ TEST_CASE("json_view") "\"", "\"abc", "\"\\x\"", "\"\\u12\"", "\"\\ud800\"", "\"\\udc00\"", "\"\x01\"", "\"\xff\"", "\"\xc3\"", "[1]x", "/", "/*", "[\n 1,\n x\n]", // NOLINT(modernize-raw-string-literal) "1e400", "-1e400", "[1.7976931348623159e308]", "{\"a\":\n{\"b\": [1, 2,\n 3 x]}}", // (an error after every kind of value: the error is found by replaying the parser) - "[null, true, -1, 1, 1.5, \"s\", {\"a\": 1} 2]", "{\"a\": null, \"b\": -1, \"c\": 1.5, \"d\": \"s\", \"e\": {}, 1}" + R"([null, true, -1, 1, 1.5, "s", {"a": 1} 2])", R"({"a": null, "b": -1, "c": 1.5, "d": "s", "e": {}, 1})" }) { CAPTURE(text) diff --git a/tests/src/unit-locale-cpp.cpp b/tests/src/unit-locale-cpp.cpp index 19c08166c..d07eabeff 100644 --- a/tests/src/unit-locale-cpp.cpp +++ b/tests/src/unit-locale-cpp.cpp @@ -525,7 +525,7 @@ struct locale_switching_token { switched = std::setlocale(LC_NUMERIC, switch_to.c_str()) != nullptr; } - return &text[0]; + return &text[0]; // NOLINT(readability-container-data-pointer): std::string::data() is const before C++17 } std::string text; @@ -647,7 +647,7 @@ TEST_CASE("convert_float_locale_aware") // "C" -> comma locale: strtod stops at the '.', so the conversion is repeated { - locale_switching_token token("1.5", comma_locale.c_str()); + locale_switching_token token("1.5", comma_locale); double value = 0; nlohmann::detail::convert_float_locale_aware(token, 1, value); if (token.switched) @@ -660,7 +660,7 @@ TEST_CASE("convert_float_locale_aware") // the same for the other floating-point types REQUIRE(std::setlocale(LC_NUMERIC, "C") != nullptr); { - locale_switching_token token("2.25", comma_locale.c_str()); + locale_switching_token token("2.25", comma_locale); float value = 0; nlohmann::detail::convert_float_locale_aware(token, 1, value); if (token.switched) @@ -670,7 +670,7 @@ TEST_CASE("convert_float_locale_aware") } REQUIRE(std::setlocale(LC_NUMERIC, "C") != nullptr); { - locale_switching_token token("2.25", comma_locale.c_str()); + locale_switching_token token("2.25", comma_locale); long double value = 0; nlohmann::detail::convert_float_locale_aware(token, 1, value); if (token.switched) diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index 8c07ffa16..4d894e649 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp @@ -541,6 +541,7 @@ TEST_CASE("object_key_index") }; std::vector hashes; + hashes.reserve(initial); for (std::size_t i = 0; i < initial; ++i) { hashes.push_back(hash_of(i)); diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 53f501f07..367f52dfa 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1533,7 +1533,7 @@ TEST_CASE("regression tests 1") { my_json::object_t top = orig.get_ref(); top.at("x") = my_json::parse(R"({"a":{"b":1},"n":null,"arr":[10,20],"objs":[{"m":5},{"m":6}]})"); - return my_json(std::move(top)); + return my_json(std::move(top)); // NOLINT(modernize-return-braced-init-list): {top} would be an array }; SECTION("existing members") diff --git a/tests/src/unit-stream-bulk-scan.cpp b/tests/src/unit-stream-bulk-scan.cpp index 90cf702e3..8be08ee72 100644 --- a/tests/src/unit-stream-bulk-scan.cpp +++ b/tests/src/unit-stream-bulk-scan.cpp @@ -121,19 +121,6 @@ class oversized_get_area_streambuf : public std::streambuf std::array m_data{{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}; }; -// the size the oversized_get_area_streambuf claims: 3 GiB with a 64-bit -// std::size_t, else 0 to skip the test (tag dispatch, as a constant condition -// triggers MSVC's C4127) -template -std::size_t oversized_get_area_size(std::integral_constant /*unused*/) -{ - return 0; -} - -std::size_t oversized_get_area_size(std::integral_constant /*unused*/) -{ - return std::size_t{3} << 30u; -} #endif // how a test reads from the stream @@ -480,7 +467,9 @@ TEST_CASE("parsing from a std::istream scans the get area in bulk") SECTION("skipping more characters than gbump() takes at once") { // gbump() takes an int, but a get area can be larger - const std::size_t claimed = oversized_get_area_size(std::integral_constant()); + // 3 GiB with a 64-bit std::size_t, else 0 (computed without a + // condition, which would trigger MSVC's C4127) + const std::size_t claimed = (std::size_t{3} << 30u) * (sizeof(std::size_t) / 8); oversized_get_area_streambuf buf(claimed); if (claimed == 0 || static_cast(buf.in_avail()) != claimed) {