From a00c951d5244bc086446396f74b132269e3a1bd2 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 16:40:12 +0200 Subject: [PATCH] Fix CI: include cycle, GCC 4.8 literal operator spacing, and global UDLs off in the JSON_NO_AUTOMATIC_UDLS test - Suppress clang-tidy misc-header-include-cycle on the intentional mutual include of json.hpp and json_literals.hpp. - Use operator"" _json with a space for GCC 4.8 in the test's detection aliases, as the header does. - Only test the global literal operators when JSON_USE_GLOBAL_UDLS is on. Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 1 + include/nlohmann/json_literals.hpp | 1 + single_include/nlohmann/json.hpp | 2 ++ single_include/nlohmann/json_literals.hpp | 1 + tests/src/unit-no_automatic_udls.cpp | 19 +++++++++++++++---- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 6f3ec5b40..7361b9c96 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -6569,6 +6569,7 @@ struct formatter // NOLINT(cert-dcl58-c // Define JSON_NO_AUTOMATIC_UDLS to include only // where needed. #ifndef JSON_NO_AUTOMATIC_UDLS + // NOLINTNEXTLINE(misc-header-include-cycle): json_literals.hpp includes this header #include #endif diff --git a/include/nlohmann/json_literals.hpp b/include/nlohmann/json_literals.hpp index d62e0cf2e..f304039e4 100644 --- a/include/nlohmann/json_literals.hpp +++ b/include/nlohmann/json_literals.hpp @@ -12,6 +12,7 @@ #include // size_t #include // string +// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end #include // This header is included at the end of unless diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 14ae985f3..d32e8ed1e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -32859,6 +32859,7 @@ struct formatter // NOLINT(cert-dcl58-c // Define JSON_NO_AUTOMATIC_UDLS to include only // where needed. #ifndef JSON_NO_AUTOMATIC_UDLS +// NOLINTNEXTLINE(misc-header-include-cycle): json_literals.hpp includes this header // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ @@ -32874,6 +32875,7 @@ struct formatter // NOLINT(cert-dcl58-c #include // size_t #include // string +// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end // #include diff --git a/single_include/nlohmann/json_literals.hpp b/single_include/nlohmann/json_literals.hpp index d62e0cf2e..f304039e4 100644 --- a/single_include/nlohmann/json_literals.hpp +++ b/single_include/nlohmann/json_literals.hpp @@ -12,6 +12,7 @@ #include // size_t #include // string +// NOLINTNEXTLINE(misc-header-include-cycle): json.hpp includes this header at its end #include // This header is included at the end of unless diff --git a/tests/src/unit-no_automatic_udls.cpp b/tests/src/unit-no_automatic_udls.cpp index 001ed4251..1a708da50 100644 --- a/tests/src/unit-no_automatic_udls.cpp +++ b/tests/src/unit-no_automatic_udls.cpp @@ -41,11 +41,20 @@ namespace // deferred to the point of instantiation, where it considers the declarations // visible from here (the global using-declarations of JSON_USE_GLOBAL_UDLS) plus // argument-dependent lookup (the literals in the library namespace). -template -using json_udl_t = decltype(operator""_json(std::declval(), std::size_t())); +#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) + template + using json_udl_t = decltype(operator""_json(std::declval(), std::size_t())); -template -using json_pointer_udl_t = decltype(operator""_json_pointer(std::declval(), std::size_t())); + template + using json_pointer_udl_t = decltype(operator""_json_pointer(std::declval(), std::size_t())); +#else + // GCC 4.8 requires a space between "" and suffix + template + using json_udl_t = decltype(operator"" _json(std::declval(), std::size_t())); + + template + using json_pointer_udl_t = decltype(operator"" _json_pointer(std::declval(), std::size_t())); +#endif template using has_json_udl = nlohmann::detail::is_detected; @@ -83,11 +92,13 @@ TEST_CASE("JSON_NO_AUTOMATIC_UDLS") TEST_CASE("JSON_NO_AUTOMATIC_UDLS with ") { +#if !defined(JSON_USE_GLOBAL_UDLS) || JSON_USE_GLOBAL_UDLS SECTION("global namespace") { CHECK("[1,2]"_json == json({1, 2})); CHECK("/a/0"_json_pointer == json::json_pointer("/a/0")); } +#endif SECTION("nlohmann::literals::json_literals") {