Fix the CI failures that the first failing TU of each job hid

- unit-stream-bulk-scan: compute the claimed size without a condition;
  the tag-dispatched template was unused with a 64-bit std::size_t
  (-Wunused-template)
- unit-json_view: give failing_allocator the typedefs, rebind and
  members that GCC 4.8's std::map takes from the allocator directly
- clang-tidy hits in the tests from #5997: raw string literals
  (unit-json_view), redundant c_str() and a NOLINT for &text[0]
  (unit-locale-cpp), reserve() before a loop (unit-ordered_json), and a
  NOLINT for a return that a braced list would turn into an array
  (unit-regression1)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-11-03 08:45:10 +01:00
1 parent cd83d48100
commit 8bcbd4735d
5 files changed
+44 -20

No files matched your search

+35 -1
View File
@@ -105,6 +105,20 @@ template<typename T>
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<typename U>
struct rebind
{
using other = failing_allocator<U>;
};
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<std::size_t>::max)() / sizeof(T);
}
template<typename U, typename... Args>
void construct(U* p, Args&& ... args) // NOLINT(readability-convert-member-functions-to-static)
{
::new (static_cast<void*>(p)) U(std::forward<Args>(args)...);
}
template<typename U>
void destroy(U* p) noexcept // NOLINT(readability-convert-member-functions-to-static)
{
static_cast<void>(p); // unused for trivially destructible types
p->~U();
}
template<typename U>
bool operator==(const failing_allocator<U>& /*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)
+4 -4
View File
@@ -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)
+1
View File
@@ -541,6 +541,7 @@ TEST_CASE("object_key_index")
};
std::vector<std::size_t> hashes;
hashes.reserve(initial);
for (std::size_t i = 0; i < initial; ++i)
{
hashes.push_back(hash_of(i));
+1 -1
View File
@@ -1533,7 +1533,7 @@ TEST_CASE("regression tests 1")
{
my_json::object_t top = orig.get_ref<const my_json::object_t&>();
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")
+3 -14
View File
@@ -121,19 +121,6 @@ class oversized_get_area_streambuf : public std::streambuf
std::array<char, 8> 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 SizeOfSizeT>
std::size_t oversized_get_area_size(std::integral_constant<std::size_t, SizeOfSizeT> /*unused*/)
{
return 0;
}
std::size_t oversized_get_area_size(std::integral_constant<std::size_t, 8> /*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<std::size_t, sizeof(std::size_t)>());
// 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<std::size_t>(buf.in_avail()) != claimed)
{