From 9a45e6ab77c53112984bc2703721fc0c68390fd0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 17 Nov 2024 11:07:35 +0100 Subject: [PATCH 1/5] :white_check_mark: add test for #4440 --- tests/src/unit-regression2.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 84e7f556e..e2275e7e8 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -42,6 +42,11 @@ using ordered_json = nlohmann::ordered_json; #endif #endif +// for #4440 +#if 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") @@ -938,6 +943,19 @@ TEST_CASE("regression tests 2") CHECK(p.x == 1); CHECK(p.y == 2); } + +#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 From b66f685f48c564fad73370522fdf24a3828e721c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 17 Nov 2024 11:11:42 +0100 Subject: [PATCH 2/5] :white_check_mark: add test for #4440 --- tests/src/unit-regression2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index e2275e7e8..93b2ca1d2 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -43,7 +43,7 @@ using ordered_json = nlohmann::ordered_json; #endif // for #4440 -#if JSON_HAS_RANGES +#ifdef JSON_HAS_RANGES #include #endif From 230b35dc157bc2eb40c4990d07b000dd6c423683 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 17 Nov 2024 11:19:20 +0100 Subject: [PATCH 3/5] :white_check_mark: add test for #4440 --- tests/src/unit-regression2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 93b2ca1d2..9da40e536 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -43,7 +43,7 @@ using ordered_json = nlohmann::ordered_json; #endif // for #4440 -#ifdef JSON_HAS_RANGES +#if JSON_HAS_RANGES == 1 #include #endif @@ -944,7 +944,7 @@ TEST_CASE("regression tests 2") CHECK(p.y == 2); } -#ifdef JSON_HAS_RANGES +#if JSON_HAS_RANGES == 1 SECTION("issue 4440") { auto noOpFilter = std::views::filter([](auto&&) From b456b88ddeaf58a2ffdc72461b07f8379be791c0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 17 Nov 2024 11:29:52 +0100 Subject: [PATCH 4/5] :white_check_mark: add test for #4440 --- tests/src/unit-regression2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 9da40e536..90a463073 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -947,7 +947,7 @@ TEST_CASE("regression tests 2") #if JSON_HAS_RANGES == 1 SECTION("issue 4440") { - auto noOpFilter = std::views::filter([](auto&&) + auto noOpFilter = std::views::filter([](auto&&) noexcept { return true; }); From a833cfde21bd3c51a84a4fde565ea6ba07751f97 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 17 Nov 2024 11:37:27 +0100 Subject: [PATCH 5/5] :white_check_mark: add test for #4440 --- tests/src/unit-regression2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 90a463073..d12751f9f 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -953,7 +953,7 @@ TEST_CASE("regression tests 2") }); json j = {1, 2, 3}; auto filtered = j | noOpFilter; - CHECK(j == *filtered.begin()); + CHECK(*filtered.begin() == 1); } #endif }