From f8b47ff6f6de8b80bea03d685d646eb93b66b98d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 16:21:53 +0200 Subject: [PATCH 1/8] Check the URL scheme before downloading in generate_docset.py (#5803) Codacy flagged two Bandit findings in the docset generator added in #5799: B310 (urlopen with an unchecked scheme) and B506 (yaml.load). download() now rejects anything but http(s) URLs before opening them, and the yaml.load call is marked, since its Loader derives from yaml.SafeLoader. The SHA-1 used to name downloaded files is marked as not used for security. Signed-off-by: Niels Lohmann --- docs/docset/generate_docset.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/docset/generate_docset.py b/docs/docset/generate_docset.py index e09e8d6d1..6f6a6e423 100755 --- a/docs/docset/generate_docset.py +++ b/docs/docset/generate_docset.py @@ -337,14 +337,17 @@ def is_remote(url) -> bool: def download(url, docs) -> str: """Download url into assets/external and return the path relative to docs.""" u = urllib.parse.urlparse(url if not url.startswith('//') else 'https:' + url) + if u.scheme.lower() not in ('http', 'https'): + raise ValueError(f'not an http(s) URL: {url}') req = urllib.request.Request(u.geturl(), headers={'User-Agent': USER_AGENT}) - with urllib.request.urlopen(req, timeout=20) as r: + # (the scheme is checked above) + with urllib.request.urlopen(req, timeout=20) as r: # nosec B310 data = r.read() ctype = r.headers.get_content_type() path = urllib.parse.unquote(u.path).lstrip('/') ext = os.path.splitext(path)[1] if u.query or not ext or path.endswith('/'): - digest = hashlib.sha1(url.encode()).hexdigest()[:12] + digest = hashlib.sha1(url.encode(), usedforsecurity=False).hexdigest()[:12] path = os.path.join(os.path.dirname(path), digest + CONTENT_TYPE_EXT.get(ctype, ext or '.bin')) rel = os.path.normpath(os.path.join('assets', 'external', u.hostname, path)) out = os.path.join(docs, rel) @@ -385,7 +388,8 @@ def localize_images(docs) -> None: def load_mkdocs_yml() -> dict: """Load mkdocs.yml, ignoring tags like !ENV and !!python/name.""" with open(MKDOCS_YML, encoding='utf-8') as f: - return yaml.load(f, Loader=Loader) + # (Loader is a yaml.SafeLoader) + return yaml.load(f, Loader=Loader) # nosec B506 def localize_site_urls(docs, site_url) -> None: From fbaa2f513e8cb6b2e9709ca2290528aaf1946557 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:37:48 +0200 Subject: [PATCH 2/8] Make max_input_size a function (GCC -Wunused-const-variable) Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/errors.hpp | 2 +- include/nlohmann/detail/view/node.hpp | 5 ++++- include/nlohmann/json_view.hpp | 2 +- tests/src/unit-json_view.cpp | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/view/errors.hpp b/include/nlohmann/detail/view/errors.hpp index 8d67a3973..06c97b552 100644 --- a/include/nlohmann/detail/view/errors.hpp +++ b/include/nlohmann/detail/view/errors.hpp @@ -55,7 +55,7 @@ template { if (f.code == error_code::input_too_large) { - // (the limit is detail::view::max_input_size: 4 GiB minus 16 bytes) + // (the limit is detail::view::max_input_size(): 4 GiB minus 16 bytes) NLOHMANN_VIEW_THROW(out_of_range::create(416, "input of 4294967280 bytes or more is not supported by json_document", nullptr)); } const BasicJsonType accepted = BasicJsonType::parse(src, src + size, nullptr, true, ignore_comments, ignore_trailing_commas); diff --git a/include/nlohmann/detail/view/node.hpp b/include/nlohmann/detail/view/node.hpp index b36fc8c2a..891424281 100644 --- a/include/nlohmann/detail/view/node.hpp +++ b/include/nlohmann/detail/view/node.hpp @@ -32,7 +32,10 @@ static_assert(static_cast(value_t::null) == 0 && static_cast detail::view::max_input_size)) + if (NLOHMANN_VIEW_UNLIKELY(size > detail::view::max_input_size())) { failure.code = detail::view::error_code::input_too_large; } diff --git a/tests/src/unit-json_view.cpp b/tests/src/unit-json_view.cpp index e9cc4ca5f..b92dcae1a 100644 --- a/tests/src/unit-json_view.cpp +++ b/tests/src/unit-json_view.cpp @@ -457,7 +457,7 @@ TEST_CASE("json_view") { // 32-bit offsets: the limit is 4 GiB minus 16 bytes (a margin below 2^32), // which is what the exception message and the documentation say - const std::size_t limit = nlohmann::detail::view::max_input_size; + const std::size_t limit = nlohmann::detail::view::max_input_size(); CHECK(limit == std::size_t{4294967279u}); const oversized_input input{limit + 1}; From 9dfeb28c4712eb13da3df93da003c8a8e682c92b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:51:23 +0200 Subject: [PATCH 3/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), and the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), plus for std::nullptr_t, and removing and edit_storage.hpp. - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions - drop edit_storage.hpp, which edit.hpp includes Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 18 ++++++++++++++++-- single_include/nlohmann/json_view.hpp | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index 7c41af7f3..4dc06cc86 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -27,7 +27,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // all_of, min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -45,6 +46,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" @@ -54,7 +69,6 @@ #include #include #include -#include #include #include #include diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 89e8e67c2..653dbcd66 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -27,7 +27,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // all_of, min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -45,6 +46,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" @@ -4119,8 +4134,6 @@ class editor } // namespace detail NLOHMANN_JSON_NAMESPACE_END -// #include - // #include // #include From 653eb310f8965f6943b90610930fa983f0230e4c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:34 +0200 Subject: [PATCH 4/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), and for std::nullptr_t, and removing . - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions - export json.hpp, keep macro_unscope.hpp, and drop the unused forward declaration of the document class Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 24 ++++++++++++++----- single_include/nlohmann/json_view.hpp | 33 +++++++++++++++++++-------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index d8b5c84ff..cc9dd2b79 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -24,7 +24,8 @@ #ifndef INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // unique_ptr @@ -32,7 +33,21 @@ #include // enable_if, integral_constant, is_base_of, is_integral, is_same, remove_cv, remove_extent #include // forward, move -#include +#include // IWYU pragma: export + +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 @@ -50,9 +65,6 @@ NLOHMANN_JSON_NAMESPACE_BEGIN -template -class basic_json_document; - /*! @brief read-only handle to one value of a basic_json_document @@ -607,6 +619,6 @@ using ordered_json_view = basic_json_view; NLOHMANN_JSON_NAMESPACE_END -#include +#include // IWYU pragma: keep #endif // INCLUDE_NLOHMANN_JSON_VIEW_HPP_ diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 94d4e0528..52d5c221c 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -24,7 +24,8 @@ #ifndef INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // unique_ptr @@ -32,7 +33,21 @@ #include // enable_if, integral_constant, is_base_of, is_integral, is_same, remove_cv, remove_extent #include // forward, move -#include +#include // IWYU pragma: export + +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 @@ -189,7 +204,10 @@ static_assert(static_cast(value_t::null) == 0 && static_cast { if (f.code == error_code::input_too_large) { - // (the limit is detail::view::max_input_size: 4 GiB minus 16 bytes) + // (the limit is detail::view::max_input_size(): 4 GiB minus 16 bytes) NLOHMANN_VIEW_THROW(out_of_range::create(416, "input of 4294967280 bytes or more is not supported by json_document", nullptr)); } const BasicJsonType accepted = BasicJsonType::parse(src, src + size, nullptr, true, ignore_comments, ignore_trailing_commas); @@ -2145,9 +2163,6 @@ NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_BEGIN -template -class basic_json_document; - /*! @brief read-only handle to one value of a basic_json_document @@ -2570,7 +2585,7 @@ class basic_json_document d.discarded = true; detail::view::parse_failure failure; bool ok = false; - if (NLOHMANN_VIEW_UNLIKELY(size > detail::view::max_input_size)) + if (NLOHMANN_VIEW_UNLIKELY(size > detail::view::max_input_size())) { failure.code = detail::view::error_code::input_too_large; } @@ -2724,6 +2739,6 @@ NLOHMANN_JSON_NAMESPACE_END #undef NLOHMANN_VIEW_THROW #undef NLOHMANN_VIEW_LITTLE_ENDIAN #undef NLOHMANN_VIEW_REPEAT16 - +// IWYU pragma: keep #endif // INCLUDE_NLOHMANN_JSON_VIEW_HPP_ From 1c62febbf3127a829b67b99f17b37aaa5a0aea32 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:35 +0200 Subject: [PATCH 5/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), and for std::nullptr_t, and removing . - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 18 +++++++++++++++++- single_include/nlohmann/json_view.hpp | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index d8895d5b7..26ca6d674 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -24,7 +24,9 @@ #ifndef INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ -#include // memcpy, size_t, strlen +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep +#include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // map #include // unique_ptr @@ -37,6 +39,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 6b271ec7b..9dc601a3c 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -24,7 +24,9 @@ #ifndef INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ -#include // memcpy, size_t, strlen +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep +#include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // map #include // unique_ptr @@ -37,6 +39,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" From 236c3b4fbe4d12bae37c16b0a0a1d7216fc20b65 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:36 +0200 Subject: [PATCH 6/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), and for std::nullptr_t, and removing . - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 18 +++++++++++++++++- single_include/nlohmann/json_view.hpp | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index 2249ac935..c51838e4e 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -25,7 +25,9 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // min -#include // memcpy, size_t, strlen +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep +#include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // map #include // unique_ptr @@ -41,6 +43,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index d80babdb6..cebd8098c 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -25,7 +25,9 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // min -#include // memcpy, size_t, strlen +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep +#include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits #include // map #include // unique_ptr @@ -41,6 +43,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" From a2840ee9382a49935c241fcd5b264025c72a77d7 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:37 +0200 Subject: [PATCH 7/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), and for std::nullptr_t, and removing . - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 17 ++++++++++++++++- single_include/nlohmann/json_view.hpp | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index f9bfd78bd..1b2fad3f4 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -25,7 +25,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -43,6 +44,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index a7ba17c90..b4db7122d 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -25,7 +25,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -43,6 +44,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" From b9b374d1b94ed46e423baefea9c066366df7703c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:38 +0200 Subject: [PATCH 8/8] Make json_view.hpp pass include-what-you-use ci_single_binaries runs IWYU with --error on every header. For json_view.hpp it suggested adding (std::array is used), the headers that json.hpp already provides (abi_config, abi_macros, input_adapters, json_pointer, cpp_future, string_concat, value_t, json_fwd), and for std::nullptr_t, and removing . - include - keep (nullptr_t, size_t; IWYU attributes them to and ) - tell IWYU not to suggest the headers that json.hpp provides: the amalgamated json_view.hpp only includes json.hpp, so including them here would duplicate their definitions - drop edit_storage.hpp, which edit.hpp includes Signed-off-by: Niels Lohmann --- include/nlohmann/json_view.hpp | 18 ++++++++++++++++-- single_include/nlohmann/json_view.hpp | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index e461b69ec..d4c110907 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -27,7 +27,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // all_of, min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint8_t, uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -45,6 +46,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" @@ -54,7 +69,6 @@ #include #include #include -#include #include #include #include diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index ea8c8fd51..e8b958af1 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -27,7 +27,8 @@ #define INCLUDE_NLOHMANN_JSON_VIEW_HPP_ #include // all_of, min -#include // size_t +#include // array +#include // nullptr_t, size_t // IWYU pragma: keep #include // uint8_t, uint32_t #include // memcpy, strlen #include // distance, input_iterator_tag, iterator_traits @@ -45,6 +46,20 @@ #include // IWYU pragma: export +// json.hpp provides the library's types and macros used below (it includes +// the headers that define them); json_view.hpp must not include them again, +// because the amalgamated json_view.hpp only includes json.hpp +// IWYU pragma: no_include +// IWYU pragma: no_include "nlohmann/detail/abi_config.hpp" +// IWYU pragma: no_include "nlohmann/detail/abi_macros.hpp" +// IWYU pragma: no_include "nlohmann/detail/input/input_adapters.hpp" +// IWYU pragma: no_include "nlohmann/detail/json_pointer.hpp" +// IWYU pragma: no_include "nlohmann/detail/meta/cpp_future.hpp" +// IWYU pragma: no_include "nlohmann/detail/string_concat.hpp" +// IWYU pragma: no_include "nlohmann/detail/value_t.hpp" +// IWYU pragma: no_include "nlohmann/json.hpp" +// IWYU pragma: no_include "nlohmann/json_fwd.hpp" + // the view builds on internals of the library: both must be the same version #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0 #error "json_view.hpp requires json.hpp of the same version (3.12.0)" @@ -4122,8 +4137,6 @@ class editor } // namespace detail NLOHMANN_JSON_NAMESPACE_END -// #include - // #include // #include