From c51c9cefeae50e75cb30200d272aee19d804f091 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 9 May 2026 11:13:05 +0200 Subject: [PATCH 1/3] :white_check_mark: add regression test for #4440 Signed-off-by: Niels Lohmann --- tests/src/unit-regression2.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 64deba4480..d8abfaabfc 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -66,6 +66,11 @@ using ordered_json = nlohmann::ordered_json; #endif #endif +// for #4440 +#if JSON_HAS_RANGES == 1 + #include +#endif + // NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") @@ -1134,6 +1139,20 @@ TEST_CASE("regression tests 2") CHECK(!result.has_value()); } #endif + +#if JSON_HAS_RANGES == 1 + SECTION("issue #4440 - assert when using std::views::filter and GCC 10") + { + auto noOpFilter = std::views::filter([](auto&&) noexcept + { + return true; + }); + json j = {1, 2, 3}; + auto filtered = j | noOpFilter; + CHECK(*filtered.begin() == 1); + } +#endif + } TEST_CASE_TEMPLATE("issue #4798 - nlohmann::json::to_msgpack() encode float NaN as double", T, double, float) // NOLINT(readability-math-missing-parentheses, bugprone-throwing-static-initialization) From 2030ba394493fc9166c2a076675e5f67f200863a Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 18 May 2026 15:54:44 +0200 Subject: [PATCH 2/3] :bug: exclude breaking libraries Signed-off-by: Niels Lohmann --- include/nlohmann/detail/macro_scope.hpp | 6 ++++++ single_include/nlohmann/json.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index fceebda06e..734414e0e4 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -137,6 +137,12 @@ // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 + // libstdc++ < 12 has incomplete C++20 ranges (issue #4440) + #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12 + #define JSON_HAS_RANGES 0 + // libc++ < 16 has incomplete C++20 ranges (issue #4440) + #elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000 + #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) #define JSON_HAS_RANGES 1 #else diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 0a1ea1d0ed..6dbeba757f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2501,6 +2501,12 @@ JSON_HEDLEY_DIAGNOSTIC_POP // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 + // libstdc++ < 12 has incomplete C++20 ranges (issue #4440) + #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12 + #define JSON_HAS_RANGES 0 + // libc++ < 16 has incomplete C++20 ranges (issue #4440) + #elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000 + #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) #define JSON_HAS_RANGES 1 #else From 6fd3913e4e1b3935143aea7e528abecc335446dc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 18 May 2026 20:40:36 +0200 Subject: [PATCH 3/3] :bug: exclude breaking libraries Signed-off-by: Niels Lohmann --- include/nlohmann/detail/macro_scope.hpp | 7 +++++-- single_include/nlohmann/json.hpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 734414e0e4..c695f26c4c 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -137,10 +137,13 @@ // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 - // libstdc++ < 12 has incomplete C++20 ranges (issue #4440) - #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12 + // libstdc++ < 11 has incomplete C++20 ranges (issue #4440) + #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11 #define JSON_HAS_RANGES 0 // libc++ < 16 has incomplete C++20 ranges (issue #4440) + #elif defined(__clang__) && !defined(__apple_build_version__) \ + && __clang_major__ < 16 && defined(__GLIBCXX__) + #define JSON_HAS_RANGES 0 #elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000 #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 6dbeba757f..9d331c61ee 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2501,10 +2501,13 @@ JSON_HEDLEY_DIAGNOSTIC_POP // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has a syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 - // libstdc++ < 12 has incomplete C++20 ranges (issue #4440) - #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 12 + // libstdc++ < 11 has incomplete C++20 ranges (issue #4440) + #elif defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11 #define JSON_HAS_RANGES 0 // libc++ < 16 has incomplete C++20 ranges (issue #4440) + #elif defined(__clang__) && !defined(__apple_build_version__) \ + && __clang_major__ < 16 && defined(__GLIBCXX__) + #define JSON_HAS_RANGES 0 #elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000 #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges)