* Fix the build of develop: tests from #5997 and #5991
- unit-msgpack-cpp17: assign the result of json::parse in
CHECK_THROWS_WITH_AS (GCC -Werror=unused-result)
- unit-json_view: failing_allocator::allocate is [[noreturn]]
(clang -Wmissing-noreturn)
- unit-class_lexer: build the quoted string once
(clang-tidy performance-inefficient-string-concatenation)
- unit-allocator: sweep_allocator provides pointer, reference and size
typedefs, which GCC 4.8's std::map takes from the allocator
- unit-allocator: skip the "sax_parse into an existing value" sweep with
iterator debugging, like the parser callback sweep: MSVC's std::vector
default constructor is noexcept but allocates its debug proxy through
the allocator, so a failing allocation in create<array_t>() terminates
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Fix the remaining CI failures of the tests from #5997 and #5991
- unit-custom-object-key-type: drop the redundant member initializer and
return a braced init list (clang-tidy); direct-initialize the converted
value, as copy-initialization makes GCC 4.8 instantiate the copy
constructor, which needs a range constructor strict_object lacks
- unit-stream-bulk-scan: pick the claimed get area size by tag dispatch
instead of a constant condition (MSVC C4127)
- unit-allocator: skip the parser callback and sax_parse sweeps with
Clang 3.4 and 3.5, which leak memory when an element constructor throws
inside a libstdc++ std::map copy or std::vector reallocation
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Fix the CI failures that the first failing TU of each job hid
- unit-stream-bulk-scan: compute the claimed size without a condition;
the tag-dispatched template was unused with a 64-bit std::size_t
(-Wunused-template)
- unit-json_view: give failing_allocator the typedefs, rebind and
members that GCC 4.8's std::map takes from the allocator directly
- clang-tidy hits in the tests from #5997: raw string literals
(unit-json_view), redundant c_str() and a NOLINT for &text[0]
(unit-locale-cpp), reserve() before a loop (unit-ordered_json), and a
NOLINT for a return that a braced list would turn into an array
(unit-regression1)
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Skip the 3 GiB get-area test with a 32-bit std::size_t in the preprocessor
The claimed size was a constant 0 on Win32, so `claimed == 0 || ...` was a
constant condition and MSVC reported C4127. Guard the section with
`#if SIZE_MAX > UINT32_MAX` instead, as unit-msgpack-custom-types.cpp does.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Silence modernize-use-transparent-functors for failing_map in unit-json_view
std::less<> needs C++14, and the test is also built as C++11.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* CI: measure line coverage without lcov's unexecuted-block adjustment
Drop geninfo_unexecuted_blocks=1 from the lcov capture of ci_test_coverage:
it reset every line of an inlined or templated function to 0 as soon as one
copy had an unexecuted block, which understated the line coverage by about
three points.
Add -fvar-tracking-assignments to both coverage builds. At -O0, GCC inlines
always_inline functions before it places the coverage counters, so the call
sites of such helpers (put_literal() and others) got no line record and
showed as 0 in an -O3 translation unit that never reaches them. With the
flag, the call sites carry counts in every translation unit. The generated
code is identical.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Remove unreachable code found by the coverage analysis
Remove code that no input can reach, and mark the lines that cannot be
covered with LCOV_EXCL_LINE:
- BJData writer: the dry_run parameter of the ND-array element writers was
always true; replace them by range checks.
- BON8 writer: call throw_integer_out_of_range() directly instead of
write_bon8_value() for values that always throw.
- binary_writer: integer_bits() is only called for integers of up to 64 bits.
- serializer, view serializer, lexer: replace guards that the callers make
unreachable by assertions or by the simpler code (surrogate pairs under
ensure_ascii, next_unget, '-' at the end of the buffer).
- json_view: drop unreachable branches in scalar(), set(), check_utf8_scan(),
append_input_impl() and unescape().
- Mark exception-cleanup braces, 2 GiB limits, big-endian and 32-bit code, and
fall-through case labels with LCOV_EXCL_LINE.
No behavior changes for any input that reaches these functions.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Tests: cover the remaining lines of the library headers
Add tests for the lines of include/nlohmann that were not covered: the
binary readers and writers, the lexer and locale paths, the json_view
modules, the custom number, key and array types, json_pointer, json_patch,
diff and the iterators.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Fix test failures in the coverage tests
- unit-custom-object-key-type: remove the unused make_strict_key(strict_key)
overload, the unused range constructor and default constructor, and guard
data() with JSON_DIAGNOSTICS (unused-function/-member-function errors with
GCC and clang -Weverything).
- unit-json_view_compare: move the two new sections to the new
unit-json_view_compare_values.cpp, as the object file got too large for the
MinGW assembler again, and use a std::map with std::greater instead of
std::unordered_map, which does not accept the incomplete basic_json
(clang 3.9, icpc).
- unit-json_view_dump: rename the variables that hid outer ones (MSVC C4456).
- unit-stream-bulk-scan: restore the real size of the oversized get area
before the adapter is destroyed (JSON_PRECISE_STREAM_POSITION reads the
character at the read position), and skip the test where the streambuf
cannot hold a get area larger than an int (MSVC).
- unit-regression1: with JSON_NO_THREAD_LOCAL, copies are built member by
member and keep correct timestamps, so check the corresponding outcome.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N5NasAgbDGG28MqXjQvLqp
Signed-off-by: Claude <noreply@anthropic.com>
* Return std::size_t from the hash helper in the ordered_json test
MSVC (Win32) rejected the implicit conversion of the unsigned long long
product to the 32-bit std::size_t (C4244 as an error). Also note when
JSON_NO_THREAD_LOCAL is set in the regression test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N5NasAgbDGG28MqXjQvLqp
Signed-off-by: Claude <noreply@anthropic.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
* Match literals without a stack array and keep parser states in bytes
scan_after_whitespace() built the expected text of true, false, and null in
local std::array objects. With -fstack-protector-strong (the default of
Ubuntu's GCC, among others), a local array gives the function a stack canary
check, which then ran on every token. scan_literal() now takes the text
after the first character as a string literal, with its length as a template
parameter; for contiguous input it compares the rest at once and falls back
to the byte loop on a mismatch, so errors are reported at the same
character. It is out of line, which keeps the token dispatch small.
The parser kept the nesting of arrays and objects in a std::vector<bool>,
whose push_back() GCC calls out of line; it is a std::vector<std::uint8_t>
now.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Skip the literal fast path test without exceptions
The test case compares the error messages of both lexer paths, so it does
not compile with JSON_NOEXCEPTION (the caught exception does not exist).
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Allow the string literal parameter of scan_literal() for clang-tidy
The parameter takes the literal by array reference so that its length is
a template parameter; this is the same exemption the C array overloads of
to_json() and from_json() have.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Make parsing from std::istream and FILE* fast
Squashed onto develop cd6b428ef (CI fixes from #5860). Original commits:
- Let the lexer's bulk fast paths run on a window of the input
- Scan the get area of an input stream in bulk
- Lock a FILE once per parse instead of once per character
- Add benchmarks for parsing from a FILE* and for many values from a stream
- Avoid implicit unsigned char to char conversion in stream tests
- Make file_input_adapter::unlock() safe to call on a moved-from adapter
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Add ABI tags for JSON_DISABLE_STREAM_BULK_SCAN and JSON_DISABLE_UNLOCKED_FILE_IO
Both macros select between two definitions of an input adapter, so
translation units compiled with different settings violated the ODR when
linked together. Like the other ABI-affecting macros, they now append a
tag to the inline namespace: _dsbs and _dufio. Their defaults move to
abi_macros.hpp so that json_fwd.hpp sees them, and the natvis file is
regenerated for the new namespaces.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Skip the exception-only checks of the stream input tests without exceptions
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>