From a2840ee9382a49935c241fcd5b264025c72a77d7 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 21:56:37 +0200 Subject: [PATCH] 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)"