Fix CI failures: constexpr, NRVO, cppcheck, IWYU (#5891)

- json_sax_dom_error_state::is_errored() cannot be constexpr: the class
  is not a literal type (GCC 4.8, GCC -Wpedantic, Clang 3.5).
- to_binary_vector: destroy the vector writer before returning, as the
  output_vector_sink sets the size of the vector in its destructor.
  Without NRVO (MSVC Debug in C++14 mode), the vector was moved out
  before it was resized.
- parser::sax_parse: return false instead of result after the early exit
  (cppcheck identicalConditionAfterEarlyExit).
- json.hpp: export detail/exceptions.hpp for IWYU, so json_view.hpp can
  name exception_id without including a detail header.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-23 22:16:26 +02:00
1 parent 0e5a906cd5
commit f8df3df021
4 files changed
+18 -10

No files matched your search

+9 -5
View File
@@ -8255,7 +8255,7 @@ NLOHMANN_JSON_NAMESPACE_END
// #include <nlohmann/detail/conversions/to_json.hpp>
// IWYU pragma: keep
// #include <nlohmann/detail/exceptions.hpp>
// IWYU pragma: export
// #include <nlohmann/detail/hash.hpp>
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
@@ -15390,7 +15390,7 @@ class json_sax_dom_error_state
return false;
}
constexpr bool is_errored() const
bool is_errored() const
{
return errored;
}
@@ -21024,7 +21024,7 @@ class parser
return finish_input(*sax, strict);
}
return result;
return false;
}
private:
@@ -37855,8 +37855,12 @@ public:
{
std::vector<std::uint8_t> result;
result.reserve(detail::binary_initial_capacity(j));
auto writer = vector_writer(result, error_handler);
write(writer);
{
// the sink sets the size of result when it is destroyed, which
// must happen before result is returned (without NRVO, it is moved)
auto writer = vector_writer(result, error_handler);
write(writer);
}
return result;
}