[libcxx-commits] [libcxx] ad41d1e - [libc++][test] zip_view test cleanups

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 8 15:34:40 PST 2023


Author: Casey Carter
Date: 2023-01-08T15:34:30-08:00
New Revision: ad41d1e26b12855fbb2b3104580a8d2b63bd5827

URL: https://github.com/llvm/llvm-project/commit/ad41d1e26b12855fbb2b3104580a8d2b63bd5827
DIFF: https://github.com/llvm/llvm-project/commit/ad41d1e26b12855fbb2b3104580a8d2b63bd5827.diff

LOG: [libc++][test] zip_view test cleanups

* The reference type of `common_input_iterator<const int*>` can't be `int&`, because an lvalue of type `const int` _can't_ bind to an `int&`. Fix by changing the return type of `operator*` to `decltype(auto)` to make it fully generic.
* `range.zip/iterator/compare.pass.cpp` verifies that the iterators of a `zip_view` don't support `<=>` when the underlying iterators do not; this is not true after LWG-3692.
* libc++ doesn't yet implement P2165R4 "Compatibility between tuple, pair and tuple-like objects", so the tests expect `zip_view` to use `pair` in places where the working draft requires `tuple`.

Differential Revision: https://reviews.llvm.org/D141216

Added: 
    

Modified: 
    libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.zip/types.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp
index dec96151959d..ea5953cefa0f 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp
@@ -63,7 +63,11 @@ constexpr bool test() {
         std::ranges::zip_view<std::ranges::zip_view<SizedRandomAccessView, SizedRandomAccessView>>> decltype(auto) v2 =
         std::views::zip(v);
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<std::ranges::range_reference_t<decltype(v2)>, std::tuple<std::pair<int&, int&>>>);
+#else
+    static_assert(std::is_same_v<std::ranges::range_reference_t<decltype(v2)>, std::tuple<std::tuple<int&, int&>>>);
+#endif
   }
   return true;
 }

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp
index 2f8b702a9fc2..f53289621eab 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp
@@ -50,10 +50,14 @@ constexpr bool test() {
     View v = View(); // the default constructor is not explicit
     assert(v.size() == 3);
     auto it = v.begin();
-    using Pair = std::pair<const int&, const int&>;
-    assert(*it++ == Pair(buff[0], buff[0]));
-    assert(*it++ == Pair(buff[1], buff[1]));
-    assert(*it == Pair(buff[2], buff[2]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
+    using Value = std::pair<const int&, const int&>;
+#else
+    using Value = std::tuple<const int&, const int&>;
+#endif
+    assert(*it++ == Value(buff[0], buff[0]));
+    assert(*it++ == Value(buff[1], buff[1]));
+    assert(*it == Value(buff[2], buff[2]));
   }
 
   return true;

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp
index f39c63519d26..19b5b9999349 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp
@@ -163,7 +163,12 @@ constexpr bool test() {
     using Subrange = std::ranges::subrange<It>;
     static_assert(!std::three_way_comparable<It>);
     using R = std::ranges::zip_view<Subrange, Subrange>;
+#ifdef _LIBCPP_VERSION
+    // libc++ hasn't implemented LWG-3692 "zip_view::iterator's operator<=> is overconstrained"
     static_assert(!std::three_way_comparable<std::ranges::iterator_t<R>>);
+#else
+    static_assert(std::three_way_comparable<std::ranges::iterator_t<R>>);
+#endif
 
     int a[] = {1, 2, 3, 4};
     int b[] = {5, 6, 7, 8, 9};

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp
index 26fdacedbf7e..569d04097219 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp
@@ -42,7 +42,11 @@ constexpr bool test() {
     auto [x, y] = *it;
     assert(&x == &(a[0]));
     assert(&y == &(b[0]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(*it), std::pair<int&, double&>>);
+#else
+    static_assert(std::is_same_v<decltype(*it), std::tuple<int&, double&>>);
+#endif
 
     x = 5;
     y = 0.1;
@@ -66,7 +70,11 @@ constexpr bool test() {
     auto it = v.begin();
     assert(&(std::get<0>(*it)) == &(a[0]));
     assert(&(std::get<1>(*it)) == &(a[0]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(*it), std::pair<int&, int const&>>);
+#else
+    static_assert(std::is_same_v<decltype(*it), std::tuple<int&, int const&>>);
+#endif
   }
   return true;
 }

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp
index b041295aed41..6b0c086d8c4f 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp
@@ -73,7 +73,11 @@ void test() {
     static_assert(std::is_same_v<Iter::iterator_concept, std::random_access_iterator_tag>);
     static_assert(std::is_same_v<Iter::iterator_category, std::input_iterator_tag>);
     static_assert(std::is_same_v<Iter::
diff erence_type, std::ptr
diff _t>);
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<int, int>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<int, int>>);
+#endif
     static_assert(HasIterCategory<Iter>);
   }
 
@@ -120,7 +124,11 @@ void test() {
     static_assert(std::is_same_v<Iter::iterator_concept, std::random_access_iterator_tag>);
     static_assert(std::is_same_v<Iter::iterator_category, std::input_iterator_tag>);
     static_assert(std::is_same_v<Iter::
diff erence_type, std::ptr
diff _t>);
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<int, std::pair<int, int>>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<int, std::tuple<int, int>>>);
+#endif
     static_assert(HasIterCategory<Iter>);
   }
 
@@ -161,7 +169,11 @@ void test() {
     // value_type of multiple views with 
diff erent value_type
     std::ranges::zip_view v{foos, bars};
     using Iter = decltype(v.begin());
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<Foo, Bar>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<Foo, Bar>>);
+#endif
   }
 
   {

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp
index 54172c245e2e..1538d763205d 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp
@@ -27,7 +27,11 @@ constexpr bool test() {
     assert(it[2] == *(it + 2));
     assert(it[4] == *(it + 4));
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(it[2]), std::pair<int&, int>>);
+#else
+    static_assert(std::is_same_v<decltype(it[2]), std::tuple<int&, int>>);
+#endif
   }
 
   {
@@ -38,7 +42,11 @@ constexpr bool test() {
     assert(it[2] == *(it + 2));
     assert(it[4] == *(it + 4));
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(it[2]), std::pair<int&, int&>>);
+#else
+    static_assert(std::is_same_v<decltype(it[2]), std::tuple<int&, int&>>);
+#endif
   }
 
   {

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.zip/types.h b/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
index 47c88e9787fe..20f8c708bab1 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
@@ -319,7 +319,7 @@ struct common_input_iterator {
   }
   constexpr void operator++(int) { ++it_; }
 
-  constexpr int& operator*() const { return *it_; }
+  constexpr decltype(auto) operator*() const { return *it_; }
 
   friend constexpr bool operator==(common_input_iterator const&, common_input_iterator const&) = default;
 };


        


More information about the libcxx-commits mailing list