Documentation:
- basic_json_view::contains: basic_json::contains(json_pointer) never
throws either; drop the claim that it does.
- std::format support is dated 3.13.0 in the serialization feature page;
std::optional is supported since 3.12.0 and std::filesystem::path since
3.10.5 in type_recipes.md.
- basic_json_view::source_offset: also -1 for values written by an edit
and arrays/objects whose elements an edit added or removed.
- basic_json_view::items: const auto& works (binds to the temporary);
by value is recommended, non-const auto& does not compile.
- basic_json_view::operator==/!=: document the overload that compares a
read-only with an editable view.
- basic_json_document::erase: out_of_range.404 also for a last token "-".
- json_editable_document/json_editable_view: mention insert and erase.
- basic_json::swap/std::swap: describe the conditional noexcept (only a
throwing move of json_base_class_t can make it throw) and that the
std::swap specialization is not provided with C++20 (ADL swap is).
- exceptions.md: out_of_range.405 also from front/pop_front and from
basic_json_document::erase with an empty pointer; other_error.502 also
for non-empty binary values in UBJSON/BJData Draft 2, as the writer does.
- Macro pages: fix highlighted lines.
Tests:
- unit-unicode.cpp: enable the "incorrect sequences" sections that were
disabled with #if 0 since 2017 without a reason. They pass; the reason
was the runtime of the quadratic high/low surrogate sweep (1024 * 64512
parses, not finished after 3 CPU minutes). That sweep is thinned to all
high surrogates against boundary code units, plus one high surrogate
against every code unit with accept(). The sections are merged into the
existing "incorrect sequences" section of the same name.
Repository:
- labeler.yml: match the moved json_view feature docs folder.
- check_amalgamation.yml: take config_json_view.json from develop's tools.
- FILES.md: list json_view_benchmarks.yml.
- cmake/ci.cmake: remove the unused targets ci_test_amalgamation (a
duplicate of make check-amalgamation), ci_benchmarks and ci_clean, and
the .gitignore entry of the first.
- make clean and .gitignore cover all tests/*_fuzzer binaries.
- hedley_undef.hpp: regenerate with make update_hedley_undef (one line
moves into sorted order); regenerate the amalgamation.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Undefine the four JSON_HEDLEY_* macros that leak after including json.hpp
include/nlohmann/detail/macro_unscope.hpp includes hedley_undef.hpp to
#undef every JSON_HEDLEY_* macro so none of them leak into the including
translation unit. Four macros were missing from that list and therefore
stayed defined after #include <nlohmann/json.hpp>:
- JSON_HEDLEY_PRAGMA
- JSON_HEDLEY_PREDICT_TRUE
- JSON_HEDLEY_PREDICT_FALSE
- JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE
hedley_undef.hpp is generated (via `make update_hedley`) by grepping
hedley.hpp for its own internal `#undef JSON_HEDLEY_X` redefinition
guards. JSON_HEDLEY_PRAGMA/PREDICT_TRUE/PREDICT_FALSE have no such guard
in upstream Hedley, so they were never picked up. The guard for
JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE also has an upstream typo
(`JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE`), so hedley_undef.hpp
was undefining the wrong (never-defined) name.
Fixes:
- include/nlohmann/thirdparty/hedley/hedley_undef.hpp: corrected the
DECLSPEC_ATTRIBUTE typo and added the three missing #undef lines,
keeping the file's alphabetical ordering.
- Makefile (update_hedley target): changed hedley_undef.hpp generation to
extract macro names directly from every `#define JSON_HEDLEY_...` in
hedley.hpp instead of from existing `#undef` guards, so a future
`make update_hedley` run undefines every macro Hedley actually defines,
even ones without a pre-existing redefinition guard. This was not run
in this PR (it would also pull in an unrelated upstream Hedley sync);
hedley_undef.hpp was hand-patched instead and single_include was
regenerated with `make amalgamate`.
- tests/src/unit-no-macro-leak.cpp: new regression test (picked up
automatically by tests/CMakeLists.txt's existing unit-*.cpp glob) that
includes json.hpp and then #ifdef/#error-checks every JSON_HEDLEY_*
macro name, so any future leak of any of the 151 vendored macros fails
the build, not just the four fixed here.
Fixes#5408.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Derive the JSON_HEDLEY_* leak-check test from hedley.hpp at build time
tests/src/unit-no-macro-leak.cpp previously hardcoded a static list of
~151 #ifdef/#error checks, one per JSON_HEDLEY_* macro name known at the
time it was written. That list would silently go stale the next time
`make update_hedley` pulls in a vendor update that adds, removes, or
renames a macro, since nothing would force it to be regenerated.
Add cmake/scripts/gen_hedley_undef_check.cmake, which derives the full
list of JSON_HEDLEY_* macro names directly from
include/nlohmann/thirdparty/hedley/hedley.hpp:
- tests/CMakeLists.txt uses it (MODE=checks) to (re)generate
hedley_undef_checks.inc at configure and build time, and wires the
generating custom target as a dependency of the test-no-macro-leak_cpp*
targets so it can never build against a stale copy. unit-no-macro-leak.cpp
now just #include-s the generated file inside its TEST_CASE instead of
carrying the checks itself.
- The Makefile's `update_hedley` target now delegates hedley_undef.hpp
generation to the same script (MODE=undef, new `update_hedley_undef`
target), so the vendored header, the generated #undef list, and the
generated test checks are all derived from the same extraction logic and
cannot drift apart.
This mirrors the approach taken independently in #5415 for the same
issue (#5408), credited there to a self-regenerating mechanism that
"can never drift again" -- ported into this branch instead of the
static list originally proposed here.
Verified with a local CMake configure + build + ctest, both against
include/ (JSON_MultipleHeaders=ON) and against the amalgamated
single_include/nlohmann/json.hpp (JSON_MultipleHeaders=OFF), and by
temporarily deleting a #undef line from hedley_undef.hpp to confirm the
generated test actually fails on a real leak.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* Fix REUSE compliance failure in gen_hedley_undef_check.cmake
The generated file's embedded banner contains the literal text
'SPDX-License-Identifier: MIT' as part of the *content* being written
to hedley_undef.hpp, not as this .cmake script's own REUSE header (it
is already covered by the blanket 'Files: *' rule in .reuse/dep5).
The reuse tool matched that embedded line as an SPDX tag for the
script itself and failed to parse the trailing 'MIT\n")' as a valid
SPDX License Expression, breaking ci_reuse_compliance. Wrap the
embedded banner in REUSE-IgnoreStart/REUSE-IgnoreEnd comments, as
recommended by the tool's own diagnostic output.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>