From d746f871c098c110f81d9883fb18b31e9ddbb7a0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 31 Oct 2026 20:22:33 +0100 Subject: [PATCH] Fix ci_clang_tidy and ci_test_noexceptions for the BSON writer ci_clang_tidy (modernize-use-auto) flagged the cast initialization in bson_entry_fits(); ci_test_noexceptions aborted in the "errors at every position" section of unit-bson.cpp, whose entries all throw, so that section now needs exceptions like the rest of the error checks. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/output/binary_writer.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- tests/src/unit-bson.cpp | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 399c567fa..5f56229f9 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -2400,7 +2400,7 @@ class binary_writer /// the 32-bit size of BSON bool bson_entry_fits(const std::size_t start, const std::size_t entry_size, const std::size_t open_containers) const noexcept { - const std::size_t limit = static_cast((std::numeric_limits::max)()); + const auto limit = static_cast((std::numeric_limits::max)()); const std::size_t written = oa.written() - start; return written <= limit && entry_size <= limit - written && open_containers <= limit - written - entry_size; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 457129749..a462b9bc0 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -29649,7 +29649,7 @@ class binary_writer /// the 32-bit size of BSON bool bson_entry_fits(const std::size_t start, const std::size_t entry_size, const std::size_t open_containers) const noexcept { - const std::size_t limit = static_cast((std::numeric_limits::max)()); + const auto limit = static_cast((std::numeric_limits::max)()); const std::size_t written = oa.written() - start; return written <= limit && entry_size <= limit - written && open_containers <= limit - written - entry_size; } diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 3d1482d5e..a65ec60a8 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -2357,6 +2357,8 @@ TEST_CASE("BSON written in one pass and in two passes") } } +#if !defined(JSON_NOEXCEPTION) + // every entry here throws, which aborts without exceptions SECTION("errors at every position") { // an entry that cannot be written, at each place among valid ones @@ -2395,4 +2397,5 @@ TEST_CASE("BSON written in one pass and in two passes") } } } +#endif }