[libcxx-commits] [libcxx] [libc++] Fix _CopySegment helper in ranges::copy(join_view, out) when called in a static assertion context (PR #69593)

Rajveer Singh Bharadwaj via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 19 12:50:06 PDT 2023


https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/69593

>From a7fe8b86a94b6f855ed66be6db805b857168875b Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
Date: Thu, 19 Oct 2023 17:08:57 +0530
Subject: [PATCH] [libc++] Fix _CopySegment helper in ranges::copy(join_view,
 out) when called in a static assertion context

Part of Issue #69083
---
 libcxx/include/__algorithm/copy.h                 |  5 +++--
 .../alg.copy/ranges.copy.segmented.pass.cpp       | 15 +++++++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__algorithm/copy.h b/libcxx/include/__algorithm/copy.h
index dfe9898c6480cf8..b35c6fa04a38149 100644
--- a/libcxx/include/__algorithm/copy.h
+++ b/libcxx/include/__algorithm/copy.h
@@ -51,9 +51,10 @@ struct __copy_loop {
 
     _OutIter& __result_;
 
-    _LIBCPP_HIDE_FROM_ABI _CopySegment(_OutIter& __result) : __result_(__result) {}
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _CopySegment(_OutIter& __result)
+        : __result_(__result) {}
 
-    _LIBCPP_HIDE_FROM_ABI void
+    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
     operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
       __result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
     }
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
index abb9157df9abbbb..50fb479afcd0640 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy.segmented.pass.cpp
@@ -92,10 +92,7 @@ constexpr void test_join_view() {
   }
 }
 
-int main(int, char**) {
-  test_containers<std::deque<int>, std::deque<int>>();
-  test_containers<std::deque<int>, std::vector<int>>();
-  test_containers<std::vector<int>, std::deque<int>>();
+constexpr bool test_constexpr() {
   test_containers<std::vector<int>, std::vector<int>>();
 
   types::for_each(types::forward_iterator_list<int*>{}, []<class Iter> {
@@ -103,6 +100,16 @@ int main(int, char**) {
     test_join_view<Iter, sentinel_wrapper<Iter>>();
     test_join_view<Iter, sized_sentinel<Iter>>();
   });
+  return true;
+}
+
+int main(int, char**) {
+  test_containers<std::deque<int>, std::deque<int>>();
+  test_containers<std::deque<int>, std::vector<int>>();
+  test_containers<std::vector<int>, std::deque<int>>();
+
+  test_constexpr();
+  static_assert(test_constexpr());
 
   return 0;
 }



More information about the libcxx-commits mailing list