[libcxx-commits] [libcxx] 770602c - [libc++] Various cleanups in the ranges tests

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 30 09:46:41 PDT 2021


Author: Louis Dionne
Date: 2021-08-30T12:46:32-04:00
New Revision: 770602cfa01346db58417fa2f6bfd49f8ed4e9fa

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

LOG: [libc++] Various cleanups in the ranges tests

- Rename test files to follow conventions better
- Split constructor tests that were in a single file
- Add missing tests for take_view and transform_view's default constructors
- Add missing tests for transform_view's view/function constructor
- Fix include guards
- Mark some tests as being specific to libc++

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

Added: 
    libcxx/test/std/ranges/range.access/range.access.begin/incomplete.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.cend/incomplete.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.end/incomplete.verify.cpp
    libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.view.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.take/ctor.default.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.take/ctor.view_count.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.transform/ctor.default.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.transform/ctor.view_function.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/borrowed_range.compile.pass.cpp
    libcxx/test/std/ranges/range.req/range.range/borrowed_range.subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/advance.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end_size.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor.range.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor.range_size.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/get.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/primitives.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/structured_bindings.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/types.h

Modified: 
    libcxx/test/std/ranges/range.access/range.prim/data.incomplete.verify.cpp
    libcxx/test/std/ranges/range.access/range.prim/empty.incomplete.verify.cpp
    libcxx/test/std/ranges/range.adaptors/range.drop/dangling.cache.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.transform/types.h

Removed: 
    libcxx/test/std/ranges/range.access/range.access.begin/incomplete.compile.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.compile.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.cend/incomplete.compile.verify.cpp
    libcxx/test/std/ranges/range.access/range.access.end/incomplete.compile.verify.cpp
    libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.base.pass.cpp
    libcxx/test/std/ranges/range.adaptors/range.take/ctor.pass.cpp
    libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
    libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/access/advance.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/access/get.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/access/primitives.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/access/structured_binding.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end_size.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor/pair_like_conv.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor/range.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/ctor/range_size.pass.cpp
    libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h


################################################################################
diff  --git a/libcxx/test/std/ranges/range.access/range.access.begin/incomplete.compile.verify.cpp b/libcxx/test/std/ranges/range.access/range.access.begin/incomplete.verify.cpp
similarity index 79%
rename from libcxx/test/std/ranges/range.access/range.access.begin/incomplete.compile.verify.cpp
rename to libcxx/test/std/ranges/range.access/range.access.begin/incomplete.verify.cpp
index 9399ffc7a4da..49ecaed00670 100644
--- a/libcxx/test/std/ranges/range.access/range.access.begin/incomplete.compile.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.access.begin/incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// unspecified begin;
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::begin on an array of incomplete type.
 
 #include <ranges>
 
@@ -18,21 +20,17 @@
 
 using begin_t = decltype(std::ranges::begin);
 
-template <class T>
-requires(!std::invocable<begin_t&, T>)
-void f() {}
+template <class T> void f() requires std::invocable<begin_t&, T> { }
+template <class T> void f() { }
 
 void test() {
   struct incomplete;
   f<incomplete(&)[]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
   f<incomplete(&)[10]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
   f<incomplete(&)[2][2]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
 
   // This is okay because calling `std::ranges::begin` on any rvalue is ill-formed.
   f<incomplete(&&)[10]>();

diff  --git a/libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.compile.verify.cpp b/libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.verify.cpp
similarity index 76%
rename from libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.compile.verify.cpp
rename to libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.verify.cpp
index a477822e90cb..ca9036d44760 100644
--- a/libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.compile.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.access.cbegin/incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// ranges::cbegin;
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::cbegin on an array of incomplete type.
 
 #include <ranges>
 
@@ -18,15 +20,13 @@
 
 using cbegin_t = decltype(std::ranges::cbegin);
 
-template <class T>
-requires(!std::invocable<cbegin_t&, T>)
-void f() {}
+template <class T> void f() requires std::invocable<cbegin_t&, T> { }
+template <class T> void f() { }
 
 void test() {
   struct incomplete;
   f<incomplete(&)[10]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
 
   // This is okay because calling `std::ranges::end` on any rvalue is ill-formed.
   f<incomplete(&&)[10]>();

diff  --git a/libcxx/test/std/ranges/range.access/range.access.cend/incomplete.compile.verify.cpp b/libcxx/test/std/ranges/range.access/range.access.cend/incomplete.verify.cpp
similarity index 83%
rename from libcxx/test/std/ranges/range.access/range.access.cend/incomplete.compile.verify.cpp
rename to libcxx/test/std/ranges/range.access/range.access.cend/incomplete.verify.cpp
index 306c662d5746..c0aff19614bb 100644
--- a/libcxx/test/std/ranges/range.access/range.access.cend/incomplete.compile.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.access.cend/incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// unspecified begin;
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::cend on an array of incomplete type.
 
 #include <ranges>
 
@@ -18,9 +20,8 @@
 
 using cend_t = decltype(std::ranges::cend);
 
-template <class T>
-requires(!std::invocable<cend_t&, T>)
-void f() {}
+template <class T> void f() requires std::invocable<cend_t&, T> { }
+template <class T> void f() { }
 
 void test() {
   struct incomplete;
@@ -30,10 +31,8 @@ void test() {
   f<incomplete(&)[10]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
   // expected-error@*:* {{"`std::ranges::end` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -3 {{no matching function for call to 'f'}}
   f<incomplete(&)[2][2]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
 
   // This is okay because calling `std::ranges::end` on any rvalue is ill-formed.
   f<incomplete(&&)[10]>();

diff  --git a/libcxx/test/std/ranges/range.access/range.access.end/incomplete.compile.verify.cpp b/libcxx/test/std/ranges/range.access/range.access.end/incomplete.verify.cpp
similarity index 83%
rename from libcxx/test/std/ranges/range.access/range.access.end/incomplete.compile.verify.cpp
rename to libcxx/test/std/ranges/range.access/range.access.end/incomplete.verify.cpp
index 4980d6ae8c79..fe860ebfc199 100644
--- a/libcxx/test/std/ranges/range.access/range.access.end/incomplete.compile.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.access.end/incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// unspecified begin;
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::end on an array of incomplete type.
 
 #include <ranges>
 
@@ -18,9 +20,8 @@
 
 using end_t = decltype(std::ranges::end);
 
-template <class T>
-requires(!std::invocable<end_t&, T>)
-void f() {}
+template <class T> void f() requires std::invocable<end_t&, T> { }
+template <class T> void f() { }
 
 void test() {
   struct incomplete;
@@ -30,10 +31,8 @@ void test() {
   f<incomplete(&)[10]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
   // expected-error@*:* {{"`std::ranges::end` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -3 {{no matching function for call to 'f'}}
   f<incomplete(&)[2][2]>();
   // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
-  // expected-error at -2 {{no matching function for call to 'f'}}
 
   // This is okay because calling `std::ranges::end` on any rvalue is ill-formed.
   f<incomplete(&&)[10]>();

diff  --git a/libcxx/test/std/ranges/range.access/range.prim/data.incomplete.verify.cpp b/libcxx/test/std/ranges/range.access/range.prim/data.incomplete.verify.cpp
index 7877dff52a47..2b8b28fd771c 100644
--- a/libcxx/test/std/ranges/range.access/range.prim/data.incomplete.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.prim/data.incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// std::ranges::data
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::data on an array of incomplete type.
 
 #include <ranges>
 

diff  --git a/libcxx/test/std/ranges/range.access/range.prim/empty.incomplete.verify.cpp b/libcxx/test/std/ranges/range.access/range.prim/empty.incomplete.verify.cpp
index c615d6005fdf..8d32431a13b1 100644
--- a/libcxx/test/std/ranges/range.access/range.prim/empty.incomplete.verify.cpp
+++ b/libcxx/test/std/ranges/range.access/range.prim/empty.incomplete.verify.cpp
@@ -9,8 +9,10 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
+// REQUIRES: libc++
 
-// std::ranges::empty
+// Test the libc++ specific behavior that we provide a better diagnostic when calling
+// std::ranges::empty on an array of incomplete type.
 
 #include <ranges>
 

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.drop/dangling.cache.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.drop/dangling.cache.pass.cpp
index d1c5c041207e..305624f127fe 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.drop/dangling.cache.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.drop/dangling.cache.pass.cpp
@@ -32,7 +32,7 @@ struct ZeroOnDestroy : std::ranges::view_base {
   constexpr ForwardIter end() const { return ForwardIter(); }
 
   ~ZeroOnDestroy() {
-    memset(buff, 0, sizeof(buff));
+    std::memset(buff, 0, sizeof(buff));
   }
 
   static auto dropFirstFour() {

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.base.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.view.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.base.pass.cpp
rename to libcxx/test/std/ranges/range.adaptors/range.join.view/ctor.view.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.take/ctor.default.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.take/ctor.default.pass.cpp
new file mode 100644
index 000000000000..3222bd2fcd7e
--- /dev/null
+++ b/libcxx/test/std/ranges/range.adaptors/range.take/ctor.default.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// take_view() requires default_initializable<V> = default;
+
+#include <ranges>
+#include <cassert>
+
+int buff[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+struct DefaultConstructible : std::ranges::view_base {
+  constexpr DefaultConstructible() : begin_(buff), end_(buff + 8) { }
+  constexpr int const* begin() const { return begin_; }
+  constexpr int const* end() const { return end_; }
+private:
+  int const* begin_;
+  int const* end_;
+};
+
+struct NonDefaultConstructible : std::ranges::view_base {
+  NonDefaultConstructible() = delete;
+  int* begin() const;
+  int* end() const;
+};
+
+constexpr bool test() {
+  {
+    std::ranges::take_view<DefaultConstructible> tv;
+    assert(tv.begin() == buff);
+    assert(tv.size() == 0);
+  }
+
+  // Test SFINAE-friendliness
+  {
+    static_assert( std::is_default_constructible_v<std::ranges::take_view<DefaultConstructible>>);
+    static_assert(!std::is_default_constructible_v<std::ranges::take_view<NonDefaultConstructible>>);
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.take/ctor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.take/ctor.view_count.pass.cpp
similarity index 56%
rename from libcxx/test/std/ranges/range.adaptors/range.take/ctor.pass.cpp
rename to libcxx/test/std/ranges/range.adaptors/range.take/ctor.view_count.pass.cpp
index 926fec790782..dabd5034f85a 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.take/ctor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.take/ctor.view_count.pass.cpp
@@ -10,7 +10,6 @@
 // UNSUPPORTED: libcpp-no-concepts
 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
 
-// take_view() requires default_initializable<V> = default;
 // constexpr take_view(V base, range_
diff erence_t<V> count);
 
 #include <ranges>
@@ -21,27 +20,6 @@
 #include "test_range.h"
 #include "types.h"
 
-int globalBuffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
-
-template<bool IsDefaultCtorable>
-struct DefaultConstructible : std::ranges::view_base {
-  DefaultConstructible() requires IsDefaultCtorable = default;
-  DefaultConstructible(int*);
-  int* begin();
-  sentinel_wrapper<int*> end();
-};
-
-struct SizedRandomAccessViewToGlobal : std::ranges::view_base {
-  RandomAccessIter begin() { return RandomAccessIter(globalBuffer); }
-  RandomAccessIter begin() const { return RandomAccessIter(globalBuffer); }
-  sentinel_wrapper<RandomAccessIter> end() {
-    return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(globalBuffer + 8)};
-  }
-  sentinel_wrapper<RandomAccessIter> end() const {
-    return sentinel_wrapper<RandomAccessIter>{RandomAccessIter(globalBuffer + 8)};
-  }
-};
-
 constexpr bool test() {
   int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
 
@@ -70,13 +48,5 @@ int main(int, char**) {
   test();
   static_assert(test());
 
-  // Tests for the default ctor.
-  static_assert( std::default_initializable<DefaultConstructible<true>>);
-  static_assert(!std::default_initializable<DefaultConstructible<false>>);
-
-  std::ranges::take_view<SizedRandomAccessViewToGlobal> tv;
-  assert(*tv.base().begin() == 1);
-  assert(tv.size() == 0);
-
   return 0;
 }

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.default.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.default.pass.cpp
new file mode 100644
index 000000000000..b020b6ef3bf8
--- /dev/null
+++ b/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.default.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// transform_view() requires std::default_initializable<V> &&
+//                           std::default_initializable<F> = default;
+
+#include <ranges>
+
+#include <cassert>
+#include <type_traits>
+
+constexpr int buff[] = {1, 2, 3};
+
+struct DefaultConstructibleView : std::ranges::view_base {
+  constexpr DefaultConstructibleView() : begin_(buff), end_(buff + 3) { }
+  constexpr int const* begin() const { return begin_; }
+  constexpr int const* end() const { return end_; }
+private:
+  int const* begin_;
+  int const* end_;
+};
+
+struct DefaultConstructibleFunction {
+  int state_;
+  constexpr DefaultConstructibleFunction() : state_(100) { }
+  constexpr int operator()(int i) const { return i + state_; }
+};
+
+struct NoDefaultView : std::ranges::view_base {
+  NoDefaultView() = delete;
+  int* begin() const;
+  int* end() const;
+};
+
+struct NoDefaultFunction {
+  NoDefaultFunction() = delete;
+  constexpr int operator()(int i) const;
+};
+
+constexpr bool test() {
+  {
+    std::ranges::transform_view<DefaultConstructibleView, DefaultConstructibleFunction> view;
+    assert(view.size() == 3);
+    assert(view[0] == 101);
+    assert(view[1] == 102);
+    assert(view[2] == 103);
+  }
+
+  {
+    std::ranges::transform_view<DefaultConstructibleView, DefaultConstructibleFunction> view = {};
+    assert(view.size() == 3);
+    assert(view[0] == 101);
+    assert(view[1] == 102);
+    assert(view[2] == 103);
+  }
+
+  static_assert(!std::is_default_constructible_v<std::ranges::transform_view<NoDefaultView,            DefaultConstructibleFunction>>);
+  static_assert(!std::is_default_constructible_v<std::ranges::transform_view<DefaultConstructibleView, NoDefaultFunction>>);
+  static_assert(!std::is_default_constructible_v<std::ranges::transform_view<NoDefaultView,            NoDefaultFunction>>);
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.view_function.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.view_function.pass.cpp
new file mode 100644
index 000000000000..759dca6e95fe
--- /dev/null
+++ b/libcxx/test/std/ranges/range.adaptors/range.transform/ctor.view_function.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// constexpr transform_view(View, F);
+
+#include <ranges>
+
+#include <cassert>
+
+struct Range : std::ranges::view_base {
+  constexpr explicit Range(int* b, int* e) : begin_(b), end_(e) { }
+  constexpr int* begin() const { return begin_; }
+  constexpr int* end() const { return end_; }
+
+private:
+  int* begin_;
+  int* end_;
+};
+
+struct F {
+  constexpr int operator()(int i) const { return i + 100; }
+};
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  {
+    Range range(buff, buff + 8);
+    F f;
+    std::ranges::transform_view<Range, F> view(range, f);
+    assert(view[0] == 101);
+    assert(view[1] == 102);
+    // ...
+    assert(view[7] == 108);
+  }
+
+  {
+    Range range(buff, buff + 8);
+    F f;
+    std::ranges::transform_view<Range, F> view = {range, f};
+    assert(view[0] == 101);
+    assert(view[1] == 102);
+    // ...
+    assert(view[7] == 108);
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}

diff  --git a/libcxx/test/std/ranges/range.adaptors/range.transform/types.h b/libcxx/test/std/ranges/range.adaptors/range.transform/types.h
index 1d535eda5db0..9c5d07935ab4 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.transform/types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range.transform/types.h
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TRANSFORM_TYPES_H
 #define TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_TRANSFORM_TYPES_H
 

diff  --git a/libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/borrowed_range.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/borrowed_range.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp b/libcxx/test/std/ranges/range.req/range.range/borrowed_range.subsumption.compile.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.range/borrowed_range.subsumption.compile.pass.cpp
rename to libcxx/test/std/ranges/range.req/range.range/borrowed_range.subsumption.compile.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/access/advance.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/advance.pass.cpp
similarity index 97%
rename from libcxx/test/std/ranges/range.utility/range.subrange/access/advance.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/advance.pass.cpp
index f27f4d0a88b1..336af63e4a3e 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/access/advance.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/advance.pass.cpp
@@ -17,7 +17,7 @@
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"
-#include "../subrange_test_types.h"
+#include "types.h"
 
 constexpr bool test() {
   std::ranges::subrange<int*> a(globalBuff, globalBuff + 8, 8);

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end.pass.cpp
similarity index 97%
rename from libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end.pass.cpp
index d65d241a596c..ea0a7903a9f6 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end.pass.cpp
@@ -14,7 +14,7 @@
 
 #include <ranges>
 
-#include "../subrange_test_types.h"
+#include "types.h"
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end_size.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end_size.pass.cpp
similarity index 98%
rename from libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end_size.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end_size.pass.cpp
index d5cf5d806716..1851ad302e7b 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/begin_end_size.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.begin_end_size.pass.cpp
@@ -14,7 +14,7 @@
 
 #include <ranges>
 
-#include "../subrange_test_types.h"
+#include "types.h"
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/pair_like_conv.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp
similarity index 98%
rename from libcxx/test/std/ranges/range.utility/range.subrange/ctor/pair_like_conv.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp
index 20cd3a799c7c..26932f8084ad 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/pair_like_conv.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp
@@ -14,7 +14,7 @@
 
 #include <ranges>
 
-#include "../subrange_test_types.h"
+#include "types.h"
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/range.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.range.pass.cpp
similarity index 98%
rename from libcxx/test/std/ranges/range.utility/range.subrange/ctor/range.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/ctor.range.pass.cpp
index 687e698433ca..f747c655df9b 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/range.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.range.pass.cpp
@@ -14,7 +14,7 @@
 
 #include <ranges>
 
-#include "../subrange_test_types.h"
+#include "types.h"
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor.range_size.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.range_size.pass.cpp
new file mode 100644
index 000000000000..04d430dc8cfc
--- /dev/null
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/ctor.range_size.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// template<borrowed_range R>
+//   requires convertible-to-non-slicing<iterator_t<R>, I> &&
+//            convertible_to<sentinel_t<R>, S>
+// constexpr subrange(R&& r, make-unsigned-like-t<iter_
diff erence_t<I>> n)
+//   requires (K == subrange_kind::sized);
+
+#include <ranges>
+#include <cassert>
+
+struct BorrowedRange {
+  constexpr explicit BorrowedRange(int* b, int* e) : begin_(b), end_(e) { }
+  constexpr int* begin() const { return begin_; }
+  constexpr int* end() const { return end_; }
+
+private:
+  int* begin_;
+  int* end_;
+};
+
+namespace std::ranges {
+  template <>
+  inline constexpr bool enable_borrowed_range<::BorrowedRange> = true;
+}
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+  using Subrange = std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>;
+
+  // Test with an empty range
+  {
+    BorrowedRange range(buff, buff);
+    Subrange subrange(range, 0);
+    assert(subrange.size() == 0);
+  }
+
+  // Test with non-empty ranges
+  {
+    BorrowedRange range(buff, buff + 1);
+    Subrange subrange(range, 1);
+    assert(subrange.size() == 1);
+  }
+  {
+    BorrowedRange range(buff, buff + 2);
+    Subrange subrange(range, 2);
+    assert(subrange[0] == 1);
+    assert(subrange[1] == 2);
+    assert(subrange.size() == 2);
+  }
+  {
+    BorrowedRange range(buff, buff + 8);
+    Subrange subrange(range, 8);
+    assert(subrange[0] == 1);
+    assert(subrange[1] == 2);
+    // ...
+    assert(subrange[7] == 8);
+    assert(subrange.size() == 8);
+  }
+
+  return true;
+}
+
+int main(int, char**) {
+  test();
+  static_assert(test());
+
+  return 0;
+}

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/range_size.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/ctor/range_size.pass.cpp
deleted file mode 100644
index 1b467b533392..000000000000
--- a/libcxx/test/std/ranges/range.utility/range.subrange/ctor/range_size.pass.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-// UNSUPPORTED: libcpp-no-concepts
-// UNSUPPORTED: libcpp-has-no-incomplete-ranges
-
-// class std::ranges::subrange;
-
-#include <ranges>
-
-// Tested in pair_like_conv.pass.cpp.
-
-int main(int, char**) {
-  return 0;
-}

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/access/get.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/get.pass.cpp
similarity index 97%
rename from libcxx/test/std/ranges/range.utility/range.subrange/access/get.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/get.pass.cpp
index 3b5bab7804d5..c546d884b020 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/access/get.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/get.pass.cpp
@@ -17,7 +17,7 @@
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"
-#include "../subrange_test_types.h"
+#include "types.h"
 
 template<size_t I, class S>
 concept GetInvocable = requires {

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/access/primitives.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/primitives.pass.cpp
similarity index 94%
rename from libcxx/test/std/ranges/range.utility/range.subrange/access/primitives.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/primitives.pass.cpp
index 4aad23953774..5cd6d95b761f 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/access/primitives.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/primitives.pass.cpp
@@ -17,9 +17,7 @@
 #include <cassert>
 #include "test_macros.h"
 #include "test_iterators.h"
-#include "../subrange_test_types.h"
-
-// Note: begin and end tested in range.subrange.ctor.pass.cpp.
+#include "types.h"
 
 constexpr bool test() {
   std::ranges::subrange<MoveOnlyForwardIter, int*> a(MoveOnlyForwardIter(globalBuff), globalBuff + 8, 8);

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/access/structured_binding.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/structured_bindings.pass.cpp
similarity index 100%
rename from libcxx/test/std/ranges/range.utility/range.subrange/access/structured_binding.pass.cpp
rename to libcxx/test/std/ranges/range.utility/range.subrange/structured_bindings.pass.cpp

diff  --git a/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h b/libcxx/test/std/ranges/range.utility/range.subrange/types.h
similarity index 97%
rename from libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h
rename to libcxx/test/std/ranges/range.utility/range.subrange/types.h
index 554966ef3dc7..8dfae99c6245 100644
--- a/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h
+++ b/libcxx/test/std/ranges/range.utility/range.subrange/types.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef SUBRANGE_TEST_TYPES_H
-#define SUBRANGE_TEST_TYPES_H
+#ifndef LIBCXX_TEST_STD_RANGES_RANGE_UTILITY_RANGE_SUBRANGE_TYPES_H
+#define LIBCXX_TEST_STD_RANGES_RANGE_UTILITY_RANGE_SUBRANGE_TYPES_H
 
 #include "test_macros.h"
 #include "test_iterators.h"
@@ -212,4 +212,4 @@ using DifferentSentinelWithSizeMemberSubrange = std::ranges::subrange<ForwardIte
                                                                       DifferentSentinelWithSizeMember::sentinel,
                                                                       std::ranges::subrange_kind::unsized>;
 
-#endif // SUBRANGE_TEST_TYPES_H
+#endif // LIBCXX_TEST_STD_RANGES_RANGE_UTILITY_RANGE_SUBRANGE_TYPES_H


        


More information about the libcxx-commits mailing list