From ff4f484e9e03b7fa4489a586d2ec1cffa0f7dcda Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 2 Sep 2024 01:48:36 +0800 Subject: [PATCH 1/2] Relax const-ness requirements on `ranges::_Meow_bound_unchecked` --- stl/inc/algorithm | 8 +++--- .../P0896R4_ranges_alg_inplace_merge/test.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 60207ef2c6..f4a56465c8 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -7064,9 +7064,9 @@ namespace ranges { template _NODISCARD constexpr _It _Lower_bound_unchecked( - _It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) { + _It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) { _STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>); - _STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>); + _STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>); using _Diff = iter_difference_t<_It>; @@ -7115,9 +7115,9 @@ namespace ranges { template _NODISCARD constexpr _It _Upper_bound_unchecked( - _It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) { + _It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) { _STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>); - _STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>); + _STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>); using _Diff = iter_difference_t<_It>; diff --git a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp index bb0314722b..f4a0eb3c58 100644 --- a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp @@ -1,12 +1,17 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include #include +#include #include #include #include +#include #include @@ -56,6 +61,26 @@ struct instantiator { } }; +// Test GH-4863: : ranges::inplace_merge doesn't seem to be able to utilize ranges::upper_bound +void test_gh_4863() { // COMPILE-ONLY + { + vector v; + auto cmp = [](int&, int&) { return false; }; + ranges::sort(v, cmp); + ranges::inplace_merge(v, v.begin(), cmp); + } + { + struct S { + operator nullptr_t() { + return nullptr; + } + }; + vector v; + auto cmp = [](const nullptr_t&, const nullptr_t&) { return false; }; + ranges::inplace_merge(v, v.begin(), cmp, [](int) { return S{}; }); + } +} + int main() { test_bidi(); } From 49861002732f31f5914c7dce1117a314e07f6cef Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 2 Sep 2024 07:13:07 +0800 Subject: [PATCH 2/2] Fix duplication of copyright banner --- tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp index f4a0eb3c58..3a9f6a495a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - #include #include #include