From b4a5a4fbbc24333e83650089030f269b881ee4db Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Thu, 22 May 2025 12:30:38 +0200 Subject: [PATCH] # This is a combination of 2 commits. # This is the 1st commit message: :white_check_mark: add test for #4440 Signed-off-by: Niels Lohmann # Conflicts: # tests/src/unit-regression2.cpp # This is the commit message #2: :white_check_mark: add 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 f9039504a..bbffb50c0 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -50,6 +50,11 @@ using ordered_json = nlohmann::ordered_json; #endif #endif +// for #4440 +#ifdef JSON_HAS_RANGES + #include +#endif + // NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") @@ -1094,6 +1099,20 @@ TEST_CASE("regression tests 2") CHECK(j.type_name() == "invalid"); } #endif + + +#ifdef JSON_HAS_RANGES + SECTION("issue 4440") + { + auto noOpFilter = std::views::filter([](auto&&) + { + return true; + }); + json j = {1, 2, 3}; + auto filtered = j | noOpFilter; + CHECK(j == *filtered.begin()); + } +#endif } DOCTEST_CLANG_SUPPRESS_WARNING_POP