Fix the develop CI failures hidden behind cancelled jobs

- ci_test_noexceptions: the JSON Patch section of unit-throw_messages
  and the strict dumps in unit-serialization catch exceptions, which
  JSON_NOEXCEPTION turns into std::abort(); skip them there.
- ci_cppcheck: insert() and iter_impl::key() ended with a call to a
  noreturn throw helper, which Cppcheck reports as missingReturn; check
  the error case first and end with the return, like the other functions.
- ci_single_binaries: ordered_map.hpp uses the Hedley macros since #5838,
  so include hedley.hpp (IWYU).
- MSVC: also wrap the second vector<json> comparison in unit-constructor2
  in parentheses.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-16 07:54:13 +02:00
1 parent 94d77f8d8d
commit ac17aad589
7 files changed
+82 -71

No files matched your search

@@ -680,12 +680,12 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
{
JSON_ASSERT(m_object != nullptr);
if (JSON_HEDLEY_LIKELY(m_object->is_object()))
if (JSON_HEDLEY_UNLIKELY(!m_object->is_object()))
{
return m_it.object_iterator->first;
throw_literal<invalid_iterator>(exception_id::iterator_key_not_object, "cannot use key() for non-object iterators", m_object);
}
throw_literal<invalid_iterator>(exception_id::iterator_key_not_object, "cannot use key() for non-object iterators", m_object);
return m_it.object_iterator->first;
}
/*!
+32 -32
View File
@@ -4895,19 +4895,19 @@ public:
iterator insert(const_iterator pos, const basic_json& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, val);
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, val);
}
/// @brief inserts element into array
@@ -4915,21 +4915,21 @@ public:
iterator insert(const_iterator pos, basic_json&& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// moving into a local first keeps this safe even if val aliases
// an element of this array
basic_json tmp(std::move(val));
return insert_iterator(pos, std::move(tmp));
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// moving into a local first keeps this safe even if val aliases
// an element of this array
basic_json tmp(std::move(val));
return insert_iterator(pos, std::move(tmp));
}
/// @brief inserts copies of element into array
@@ -4937,19 +4937,19 @@ public:
iterator insert(const_iterator pos, size_type cnt, const basic_json& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, cnt, val);
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, cnt, val);
}
/// @brief inserts range of elements into array
+1
View File
@@ -23,6 +23,7 @@
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/thirdparty/hedley/hedley.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
+37 -35
View File
@@ -20745,12 +20745,12 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
{
JSON_ASSERT(m_object != nullptr);
if (JSON_HEDLEY_LIKELY(m_object->is_object()))
if (JSON_HEDLEY_UNLIKELY(!m_object->is_object()))
{
return m_it.object_iterator->first;
throw_literal<invalid_iterator>(exception_id::iterator_key_not_object, "cannot use key() for non-object iterators", m_object);
}
throw_literal<invalid_iterator>(exception_id::iterator_key_not_object, "cannot use key() for non-object iterators", m_object);
return m_it.object_iterator->first;
}
/*!
@@ -29734,6 +29734,8 @@ NLOHMANN_JSON_NAMESPACE_END
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/thirdparty/hedley/hedley.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
@@ -34958,19 +34960,19 @@ public:
iterator insert(const_iterator pos, const basic_json& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, val);
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, val);
}
/// @brief inserts element into array
@@ -34978,21 +34980,21 @@ public:
iterator insert(const_iterator pos, basic_json&& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// moving into a local first keeps this safe even if val aliases
// an element of this array
basic_json tmp(std::move(val));
return insert_iterator(pos, std::move(tmp));
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// moving into a local first keeps this safe even if val aliases
// an element of this array
basic_json tmp(std::move(val));
return insert_iterator(pos, std::move(tmp));
}
/// @brief inserts copies of element into array
@@ -35000,19 +35002,19 @@ public:
iterator insert(const_iterator pos, size_type cnt, const basic_json& val) // NOLINT(performance-unnecessary-value-param)
{
// insert only works for arrays
if (JSON_HEDLEY_LIKELY(is_array()))
if (JSON_HEDLEY_UNLIKELY(!is_array()))
{
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, cnt, val);
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
}
detail::throw_cannot_use_with(detail::exception_id::insert_wrong_type, "insert()", *this);
// check if iterator pos fits to this JSON value
if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
{
detail::throw_literal<invalid_iterator>(detail::exception_id::iterator_from_other_value, "iterator does not fit current value", this);
}
// insert to array and return iterator
return insert_iterator(pos, cnt, val);
}
/// @brief inserts range of elements into array
+1 -1
View File
@@ -305,7 +305,7 @@ TEST_CASE("copy constructor and destructor across value types")
// mutating the copy leaves the original alone
copy[5] = "changed";
copy[6].push_back(1);
CHECK(copy != v);
CHECK((copy != v));
CHECK(v[5] == std::string(5, 'x'));
CHECK(v[6].size() == 3);
+6
View File
@@ -1374,7 +1374,13 @@ void check_dump_against_reference(const std::string& s, const bool with_strict =
};
for (const auto error_handler : error_handlers)
{
#if defined(JSON_NOEXCEPTION)
// a strict dump of invalid UTF-8 calls std::abort() instead of throwing
static_cast<void>(with_strict);
if (error_handler == json::error_handler_t::strict)
#else
if (!with_strict && error_handler == json::error_handler_t::strict)
#endif
{
continue;
}
+2
View File
@@ -94,6 +94,7 @@ TEST_CASE("exception messages of out-of-line throw sites")
CHECK_MSG(obj.update(arr.begin(), arr2.end()), "[json.exception.invalid_iterator.210] iterators do not fit");
}
#if !defined(JSON_NOEXCEPTION) // patch_msg() catches the exceptions, which JSON_NOEXCEPTION turns into std::abort()
SECTION("patch")
{
const auto patch_msg = [](const char* doc, const char* patch)
@@ -138,4 +139,5 @@ TEST_CASE("exception messages of out-of-line throw sites")
CHECK(patch_msg("{\"a\":1}", "[{\"op\":\"test\",\"path\":\"/a\",\"value\":2}]") == "[json.exception.other_error.501] unsuccessful: {\"op\":\"test\",\"path\":\"/a\",\"value\":2}");
CHECK(patch_msg("{\"a\":1}", "[{\"op\":\"move\",\"path\":\"/a\"}]") == "[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'");
}
#endif
}