Compare commits

..
Author SHA1 Message Date
Niels Lohmann d7a7534872 Tests: skip the parse() allocation sweep with MSVC iterator debugging
With _ITERATOR_DEBUG_LEVEL > 0 (MSVC STL debug builds, clang-cl), containers
allocate inside noexcept functions, so a failing allocation terminates the
program: "test case CRASHED: Terminate handler called" in the sax_parse
subcase of #5985. The sweep test of #6000 has the same guard.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-02 19:12:26 +01:00
Niels Lohmann eaee875178 json_view: no constant operand in the number dispatch (MSVC C4127)
The `!negative ||` that #6006 added to the digit test of the number scan has
a constant left operand in the template (negative is a template argument), so
MSVC reports C4127 under /WX in builder.hpp(1177). Restore the plain test; the
branch behaves the same.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-02 19:12:26 +01:00
Niels Lohmann 3724295333 json_view: a value that is not found has no bytes in its exception context
Keeping the byte range of the root value (#5990) dropped the found flag of
value_path(), but a root has no tokens and is found, while a view of a value
that was removed from the document is not found. Without the flag, the
removed value got the bytes of its stale node, and
"json_view exceptions name the path and the bytes of the value" failed on
the macOS jobs with JSON_DIAGNOSTICS and JSON_DIAGNOSTIC_POSITIONS.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-02 19:10:16 +01:00
4 changed files with 10 additions and 15 deletions

No files matched your search

+1 -2
View File
@@ -1174,9 +1174,8 @@ indent_done:
{
++p;
}
else if (!negative || NLOHMANN_VIEW_LIKELY(cur() >= '1' && cur() <= '9'))
else if (NLOHMANN_VIEW_LIKELY(cur() >= '1' && cur() <= '9'))
{
// (without a sign, the dispatch saw a digit)
p = skip_digits(p + 1, e);
}
else
+2 -5
View File
@@ -230,8 +230,7 @@ void value_range(const document_data& d, const node* n, std::size_t& start, std:
/// the context basic_json puts in front of the message of an exception about
/// a value: "(/path) " with JSON_DIAGNOSTICS (none for the root), then
/// "(bytes a-b) " with JSON_DIAGNOSTIC_POSITIONS (also for the root); with
/// JSON_DIAGNOSTICS, nothing for a value that is no longer part of the document
/// "(bytes a-b) " with JSON_DIAGNOSTIC_POSITIONS (also for the root)
///
/// This and the throw helpers that take an error_site are templates, so that
/// the path and range code is instantiated only where an exception can be
@@ -252,12 +251,10 @@ std::string diagnostics(const error_site site)
std::string context;
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
// a value that is no longer part of the document has no path, and its
// node still holds the bytes it had in the source: no context at all
const bool found = edited ? value_path<true>(d, site.value(), tokens) : value_path<false>(d, site.value(), tokens);
if (!found)
{
// context is still empty; returning it keeps the copy elided (-Wnrvo)
// a value that is not found has no path, and with it no bytes
return context;
}
if (!tokens.empty())
+3 -7
View File
@@ -2479,9 +2479,8 @@ indent_done:
{
++p;
}
else if (!negative || NLOHMANN_VIEW_LIKELY(cur() >= '1' && cur() <= '9'))
else if (NLOHMANN_VIEW_LIKELY(cur() >= '1' && cur() <= '9'))
{
// (without a sign, the dispatch saw a digit)
p = skip_digits(p + 1, e);
}
else
@@ -5059,8 +5058,7 @@ void value_range(const document_data& d, const node* n, std::size_t& start, std:
/// the context basic_json puts in front of the message of an exception about
/// a value: "(/path) " with JSON_DIAGNOSTICS (none for the root), then
/// "(bytes a-b) " with JSON_DIAGNOSTIC_POSITIONS (also for the root); with
/// JSON_DIAGNOSTICS, nothing for a value that is no longer part of the document
/// "(bytes a-b) " with JSON_DIAGNOSTIC_POSITIONS (also for the root)
///
/// This and the throw helpers that take an error_site are templates, so that
/// the path and range code is instantiated only where an exception can be
@@ -5081,12 +5079,10 @@ std::string diagnostics(const error_site site)
std::string context;
#if JSON_DIAGNOSTICS
std::vector<std::string> tokens;
// a value that is no longer part of the document has no path, and its
// node still holds the bytes it had in the source: no context at all
const bool found = edited ? value_path<true>(d, site.value(), tokens) : value_path<false>(d, site.value(), tokens);
if (!found)
{
// context is still empty; returning it keeps the copy elided (-Wnrvo)
// a value that is not found has no path, and with it no bytes
return context;
}
if (!tokens.empty())
+4 -1
View File
@@ -1026,7 +1026,10 @@ TEST_CASE("insert() provides its documented exception guarantees (#5986)")
}
#endif
#if !defined(JSON_NOEXCEPTION)
// the no-exceptions CI job has no std::bad_alloc to catch; with iterator
// debugging (MSVC STL debug builds) containers allocate inside noexcept
// functions, so failing an allocation there terminates the program
#if !defined(JSON_NOEXCEPTION) && !(defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL > 0)
namespace
{
// the allocation numbered sweep_fail_at (counted from 1) throws; 0 never fails