Keep the MinGW test objects below the linker's section limit

The MinGW clang job links with a GNU ld that cannot relocate an object
with more than 32767 sections. unit-regression2, unit-regression3 and
unit-msgpack went over it:

- At -O0, the parser and binary reader for parse(), accept() and
  from_*() still emitted the stubs that stand in for recovering, and
  the parser referenced its recovery helpers from code that never runs.
  The stubs are now always inlined, and the parser reaches its helpers
  through the same allow_recovery tag as the stubs, so that this code
  is not even instantiated there. This removes about 300 sections from
  unit-msgpack.
- Every sax_parse call instantiates the parser and binary reader that
  recover from errors. The tests that call it move from
  unit-regression2.cpp (#3989) and unit-regression3.cpp (#5676) into
  unit-sax_parse.cpp, like unit-explicit_instantiation.cpp got a file
  of its own (#5511), and CONTRIBUTING.md points there.

Section counts of the MinGW Debug objects (clang 19, -g0), develop / PR:
unit-msgpack 32281 / 32558, unit-regression2 31272 / 31278,
unit-regression3 32392 / 27462, unit-sax_parse - / 19836.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-08 10:36:16 +02:00
1 parent d1e6439187
commit f8ff0942b2
7 files changed
+863 -679

No files matched your search

@@ -483,6 +483,7 @@ class binary_reader
/// @copydoc skip_unsupported_bson_element
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
constexpr std::false_type skip_unsupported_bson_element(const char_int_type /*element_type*/) const noexcept
{
return {};
@@ -3905,6 +3906,7 @@ class binary_reader
/// @copydoc recover_high_precision_number
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
constexpr std::false_type recover_high_precision_number(const std::vector<char>& /*number_vector*/, const std::size_t /*remaining*/ = 0) const noexcept
{
return {};
@@ -5014,6 +5016,7 @@ class binary_reader
@return false, so that the caller stops reading
*/
template<typename Exception>
JSON_HEDLEY_ALWAYS_INLINE
bool report_error(const std::size_t position, const std::string& last_token, const Exception& ex)
{
close_requested = sax->parse_error(position, last_token, ex);
@@ -5050,6 +5053,7 @@ class binary_reader
/// @copydoc repair_requested
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
constexpr std::false_type repair_requested() const noexcept
{
return {};
@@ -5074,6 +5078,7 @@ class binary_reader
/// @copydoc value_failed
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
constexpr std::false_type value_failed() const noexcept
{
return {};
@@ -5124,6 +5129,7 @@ class binary_reader
/// @copydoc close_open_containers
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
void close_open_containers() const noexcept {}
/*!
@@ -5159,6 +5165,7 @@ class binary_reader
/// @copydoc resync
template < bool Recover = AllowRecovery, enable_if_t < !Recover, int > = 0 >
JSON_HEDLEY_ALWAYS_INLINE
constexpr std::false_type resync() const noexcept
{
return {};