From 389e749c42307ae589f84c79cceb175e6c9b510b Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Mon, 14 Jun 2021 10:25:13 -0400 Subject: [PATCH] [libc++] [test] Fix some GCC 11 errors/warnings in these tests. NFCI. Differential Revision: https://reviews.llvm.org/D104228 --- .../contiguous_iterator.compile.pass.cpp | 61 +++------ .../random_access_iterator.compile.pass.cpp | 82 ++++-------- .../range.access.begin/begin.pass.cpp | 117 ++++++++++-------- .../{end.cpp => end.pass.cpp} | 29 +++-- .../ranges/range.adaptors/range.all.pass.cpp | 39 +++--- .../range.subrange/subrange_test_types.h | 2 +- .../view.interface/view.interface.pass.cpp | 26 ++-- .../string.view/string.view.ops/copy.pass.cpp | 2 +- .../tuple.tuple/tuple.cnstr/deduct.pass.cpp | 2 +- 9 files changed, 159 insertions(+), 201 deletions(-) rename libcxx/test/std/ranges/range.access/range.access.end/{end.cpp => end.pass.cpp} (90%) diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp index 8a771e18935d..8596b7614d91 100644 --- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp @@ -14,15 +14,16 @@ // concept contiguous_iterator; #include +#include #include "test_iterators.h" -static_assert(!std::contiguous_iterator >); -static_assert(!std::contiguous_iterator >); -static_assert(!std::contiguous_iterator >); -static_assert(!std::contiguous_iterator >); -static_assert(!std::contiguous_iterator >); -static_assert(std::contiguous_iterator >); +static_assert(!std::contiguous_iterator>); +static_assert(!std::contiguous_iterator>); +static_assert(!std::contiguous_iterator>); +static_assert(!std::contiguous_iterator>); +static_assert(!std::contiguous_iterator>); +static_assert(std::contiguous_iterator>); static_assert(std::contiguous_iterator); static_assert(std::contiguous_iterator); @@ -42,11 +43,7 @@ struct simple_contiguous_iterator { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -68,23 +65,19 @@ struct simple_contiguous_iterator { static_assert(std::random_access_iterator); static_assert(std::contiguous_iterator); -struct missmatch_value_iter_ref_t { +struct mismatch_value_iter_ref_t { typedef std::contiguous_iterator_tag iterator_category; typedef short value_type; typedef std::ptrdiff_t difference_type; typedef int* pointer; typedef int& reference; - typedef missmatch_value_iter_ref_t self; + typedef mismatch_value_iter_ref_t self; - missmatch_value_iter_ref_t(); + mismatch_value_iter_ref_t(); reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -103,8 +96,8 @@ struct missmatch_value_iter_ref_t { reference operator[](difference_type n) const; }; -static_assert(std::random_access_iterator); -static_assert(!std::contiguous_iterator); +static_assert(std::random_access_iterator); +static_assert(!std::contiguous_iterator); struct wrong_iter_reference_t { typedef std::contiguous_iterator_tag iterator_category; @@ -118,11 +111,7 @@ struct wrong_iter_reference_t { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -156,11 +145,7 @@ struct no_element_type { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -195,11 +180,7 @@ struct to_address_wrong_return_type { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -240,11 +221,7 @@ struct template_and_no_element_type { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self& y); - friend bool operator< (const self&, const self& y); - friend bool operator<=(const self&, const self& y); - friend bool operator> (const self&, const self& y); - friend bool operator>=(const self&, const self& y); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -254,7 +231,7 @@ struct template_and_no_element_type { self& operator+=(difference_type n); self operator+(difference_type n) const; - friend self operator+(difference_type n, self x); + friend self operator+(difference_type, self) { return self{}; } self& operator-=(difference_type n); self operator-(difference_type n) const; diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/random_access_iterator.compile.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/random_access_iterator.compile.pass.cpp index 976af9d9ef81..c7e097ac9b22 100644 --- a/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/random_access_iterator.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/random_access_iterator.compile.pass.cpp @@ -18,12 +18,12 @@ #include "test_iterators.h" #include "test_macros.h" -static_assert(!std::random_access_iterator >); -static_assert(!std::random_access_iterator >); -static_assert(!std::random_access_iterator >); -static_assert(!std::random_access_iterator >); -static_assert( std::random_access_iterator >); -static_assert( std::random_access_iterator >); +static_assert(!std::random_access_iterator>); +static_assert(!std::random_access_iterator>); +static_assert(!std::random_access_iterator>); +static_assert(!std::random_access_iterator>); +static_assert( std::random_access_iterator>); +static_assert( std::random_access_iterator>); static_assert(std::random_access_iterator); static_assert(std::random_access_iterator); @@ -40,11 +40,7 @@ struct wrong_iterator_category { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self&); - friend bool operator< (const self&, const self&); - friend bool operator<=(const self&, const self&); - friend bool operator> (const self&, const self&); - friend bool operator>=(const self&, const self&); + auto operator<=>(const self&) const = default; self& operator++(); self operator++(int); @@ -76,143 +72,113 @@ struct common_base { reference operator*() const; pointer operator->() const; - friend bool operator==(const self&, const self&); - friend bool operator< (const self&, const self&); - friend bool operator<=(const self&, const self&); - friend bool operator> (const self&, const self&); - friend bool operator>=(const self&, const self&); - self& operator++(); self operator++(int); - self& operator--(); self operator--(int); + auto operator<=>(const common_base&) const = default; }; -struct simple_random_access_iterator - : common_base { - +struct simple_random_access_iterator : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); self operator-(difference_type n) const; difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert(std::bidirectional_iterator); static_assert(std::random_access_iterator); -struct no_plus_equals - : common_base { - +struct no_plus_equals : common_base { /* self& operator+=(difference_type n); */ self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); self operator-(difference_type n) const; difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct no_plus_difference_type - : common_base { - +struct no_plus_difference_type : common_base { self& operator+=(difference_type n); /* self operator+(difference_type n) const; */ friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); self operator-(difference_type n) const; difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct difference_type_no_plus - : common_base { - +struct difference_type_no_plus : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; /* friend self operator+(difference_type n, self x); */ - self& operator-=(difference_type n); self operator-(difference_type n) const; difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct no_minus_equals - : common_base { - +struct no_minus_equals : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - /* self& operator-=(difference_type n); */ self operator-(difference_type n) const; difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct no_minus - : common_base { - +struct no_minus : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); /* self operator-(difference_type n) const; */ difference_type operator-(const self&) const; - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct not_sized_sentinel - : common_base { - +struct not_sized_sentinel : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); self operator-(difference_type n) const; /* difference_type operator-(const self&) const; */ - reference operator[](difference_type n) const; + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); -struct no_subscript - : common_base { - +struct no_subscript : common_base { self& operator+=(difference_type n); self operator+(difference_type n) const; friend self operator+(difference_type n, self x); - self& operator-=(difference_type n); self operator-(difference_type n) const; difference_type operator-(const self&) const; - /* reference operator[](difference_type n) const; */ + auto operator<=>(const self&) const = default; }; static_assert( std::bidirectional_iterator); static_assert(!std::random_access_iterator); diff --git a/libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp b/libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp index 263a2c3dfeb8..1e83cdaa25f4 100644 --- a/libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp +++ b/libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp @@ -36,11 +36,14 @@ struct BeginMember { }; // Ensure that we can't call with rvalues with borrowing disabled. -static_assert( std::is_invocable_v); -static_assert( std::is_invocable_v); -static_assert(!std::is_invocable_v); +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); +static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); static_assert( std::is_invocable_v); +static_assert(!std::is_invocable_v); static_assert( std::is_invocable_v); +static_assert( std::is_invocable_v); constexpr bool testArray() { int a[2]; @@ -61,46 +64,41 @@ constexpr bool testArray() { struct BeginMemberFunction { int x; constexpr const int *begin() const { return &x; } - friend constexpr int *begin(BeginMemberFunction const& bf); + friend int *begin(BeginMemberFunction const&); }; struct BeginMemberReturnsInt { int begin() const; }; - static_assert(!std::is_invocable_v); struct BeginMemberReturnsVoidPtr { const void *begin() const; }; - static_assert(!std::is_invocable_v); -struct Empty { }; struct EmptyBeginMember { - Empty begin() const; + struct iterator {}; + iterator begin() const; }; +static_assert(!std::is_invocable_v); + struct EmptyPtrBeginMember { + struct Empty {}; Empty x; constexpr const Empty *begin() const { return &x; } }; -static_assert(!std::is_invocable_v); - -struct PtrConvertible { - operator int*() const; -}; struct PtrConvertibleBeginMember { - PtrConvertible begin() const; + struct iterator { operator int*() const; }; + iterator begin() const; }; - static_assert(!std::is_invocable_v); struct NonConstBeginMember { int x; constexpr int *begin() { return &x; } }; - static_assert( std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); @@ -109,7 +107,6 @@ static_assert(!std::is_invocable_v); struct EnabledBorrowingBeginMember { constexpr int *begin() const { return &globalBuff[0]; } }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; @@ -135,11 +132,11 @@ constexpr bool testBeginMember() { return true; } + struct BeginFunction { int x; friend constexpr const int *begin(BeginFunction const& bf) { return &bf.x; } }; - static_assert( std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); @@ -152,12 +149,15 @@ struct BeginFunctionWithDataMember { friend constexpr const int *begin(BeginFunctionWithDataMember const& bf) { return &bf.x; } }; -struct BeginFunctionWithPrivateBeginMember : private BeginMember { +struct BeginFunctionWithPrivateBeginMember { int y; friend constexpr const int *begin(BeginFunctionWithPrivateBeginMember const& bf) { return &bf.y; } +private: + const int *begin() const; }; struct BeginFunctionReturnsEmptyPtr { + struct Empty {}; Empty x; friend constexpr const Empty *begin(BeginFunctionReturnsEmptyPtr const& bf) { return &bf.x; } }; @@ -165,87 +165,104 @@ struct BeginFunctionReturnsEmptyPtr { struct BeginFunctionByValue { friend constexpr int *begin(BeginFunctionByValue) { return &globalBuff[1]; } }; - static_assert(!std::is_invocable_v); struct BeginFunctionEnabledBorrowing { friend constexpr int *begin(BeginFunctionEnabledBorrowing) { return &globalBuff[2]; } }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; struct BeginFunctionReturnsInt { - friend constexpr int begin(BeginFunctionReturnsInt const&); + friend int begin(BeginFunctionReturnsInt const&); }; - static_assert(!std::is_invocable_v); struct BeginFunctionReturnsVoidPtr { - friend constexpr void *begin(BeginFunctionReturnsVoidPtr const&); + friend void *begin(BeginFunctionReturnsVoidPtr const&); }; - static_assert(!std::is_invocable_v); struct BeginFunctionReturnsEmpty { - friend constexpr Empty begin(BeginFunctionReturnsEmpty const&); + struct Empty {}; + friend Empty begin(BeginFunctionReturnsEmpty const&); }; - static_assert(!std::is_invocable_v); struct BeginFunctionReturnsPtrConvertible { - friend constexpr PtrConvertible begin(BeginFunctionReturnsPtrConvertible const&); + struct iterator { operator int*() const; }; + friend iterator begin(BeginFunctionReturnsPtrConvertible const&); }; - static_assert(!std::is_invocable_v); constexpr bool testBeginFunction() { - const BeginFunction a{}; - assert(std::ranges::begin(a) == &a.x); - BeginFunction aa{}; + BeginFunction a{}; + const BeginFunction aa{}; + static_assert(!std::invocable); + assert(std::ranges::begin(aa) == &aa.x); + assert(std::ranges::cbegin(a) == &a.x); assert(std::ranges::cbegin(aa) == &aa.x); - BeginFunctionByValue b; + BeginFunctionByValue b{}; + const BeginFunctionByValue bb{}; assert(std::ranges::begin(b) == &globalBuff[1]); + assert(std::ranges::begin(bb) == &globalBuff[1]); assert(std::ranges::cbegin(b) == &globalBuff[1]); + assert(std::ranges::cbegin(bb) == &globalBuff[1]); - BeginFunctionEnabledBorrowing c; + BeginFunctionEnabledBorrowing c{}; + const BeginFunctionEnabledBorrowing cc{}; assert(std::ranges::begin(std::move(c)) == &globalBuff[2]); + static_assert(!std::invocable); + assert(std::ranges::begin(std::move(cc)) == &globalBuff[2]); + assert(std::ranges::cbegin(std::move(cc)) == &globalBuff[2]); - const BeginFunctionReturnsEmptyPtr d{}; - assert(std::ranges::begin(d) == &d.x); - BeginFunctionReturnsEmptyPtr dd{}; + BeginFunctionReturnsEmptyPtr d{}; + const BeginFunctionReturnsEmptyPtr dd{}; + static_assert(!std::invocable); + assert(std::ranges::begin(dd) == &dd.x); + assert(std::ranges::cbegin(d) == &d.x); assert(std::ranges::cbegin(dd) == &dd.x); - const BeginFunctionWithDataMember e{}; - assert(std::ranges::begin(e) == &e.x); - BeginFunctionWithDataMember ee{}; + BeginFunctionWithDataMember e{}; + const BeginFunctionWithDataMember ee{}; + static_assert(!std::invocable); + assert(std::ranges::begin(ee) == &ee.x); + assert(std::ranges::cbegin(e) == &e.x); assert(std::ranges::cbegin(ee) == &ee.x); - const BeginFunctionWithPrivateBeginMember f{}; - assert(std::ranges::begin(f) == &f.y); - BeginFunctionWithPrivateBeginMember ff{}; + BeginFunctionWithPrivateBeginMember f{}; + const BeginFunctionWithPrivateBeginMember ff{}; + static_assert(!std::invocable); + assert(std::ranges::begin(ff) == &ff.y); + assert(std::ranges::cbegin(f) == &f.y); assert(std::ranges::cbegin(ff) == &ff.y); return true; } + +ASSERT_NOEXCEPT(std::ranges::begin(std::declval())); +ASSERT_NOEXCEPT(std::ranges::cbegin(std::declval())); + template struct NoThrowMemberBegin { - T begin() noexcept; T begin() const noexcept; }; +ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); +ASSERT_NOEXCEPT(std::ranges::cbegin(std::declval&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval>&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::cbegin(std::declval>&>())); template struct NoThrowADLBegin { - friend T begin(NoThrowADLBegin&) noexcept; - friend T begin(NoThrowADLBegin const&) noexcept; + friend T begin(NoThrowADLBegin&) noexcept { return T{}; } + friend T begin(NoThrowADLBegin const&) noexcept { return T{}; } }; -ASSERT_NOEXCEPT(std::ranges::begin(std::declval())); -ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); -ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval >&>())); ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); -ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval >&>())); +ASSERT_NOEXCEPT(std::ranges::cbegin(std::declval&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval>&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::cbegin(std::declval>&>())); int main(int, char**) { diff --git a/libcxx/test/std/ranges/range.access/range.access.end/end.cpp b/libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp similarity index 90% rename from libcxx/test/std/ranges/range.access/range.access.end/end.cpp rename to libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp index 6949fa4cb29e..1a5d7fb75187 100644 --- a/libcxx/test/std/ranges/range.access/range.access.end/end.cpp +++ b/libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp @@ -273,26 +273,31 @@ constexpr bool testEndFunction() { return true; } + +ASSERT_NOEXCEPT(std::ranges::end(std::declval())); +ASSERT_NOEXCEPT(std::ranges::cend(std::declval())); + template struct NoThrowMemberEnd { - T begin() noexcept; - T begin() const noexcept; - T end() noexcept; + T begin() const; T end() const noexcept; }; +ASSERT_NOEXCEPT(std::ranges::end(std::declval&>())); +ASSERT_NOEXCEPT(std::ranges::cend(std::declval&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::end(std::declval>&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::cend(std::declval>&>())); template struct NoThrowADLEnd { - friend T begin(NoThrowADLEnd&) noexcept; - friend T begin(NoThrowADLEnd const&) noexcept; - friend T end(NoThrowADLEnd&) noexcept; - friend T end(NoThrowADLEnd const&) noexcept; + T begin() const; + friend T end(NoThrowADLEnd&) noexcept { return T{}; } + friend T end(NoThrowADLEnd const&) noexcept { return T{}; } }; -ASSERT_NOEXCEPT(std::ranges::begin(std::declval())); -ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); -ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval >&>())); -ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); -ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval >&>())); +ASSERT_NOEXCEPT(std::ranges::end(std::declval&>())); +ASSERT_NOEXCEPT(std::ranges::cend(std::declval&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::end(std::declval>&>())); +ASSERT_NOT_NOEXCEPT(std::ranges::cend(std::declval>&>())); + int main(int, char**) { testArray(); diff --git a/libcxx/test/std/ranges/range.adaptors/range.all.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.all.pass.cpp index 38f350a44633..46bd92857203 100644 --- a/libcxx/test/std/ranges/range.adaptors/range.all.pass.cpp +++ b/libcxx/test/std/ranges/range.adaptors/range.all.pass.cpp @@ -22,13 +22,13 @@ int globalBuff[8]; template struct View : std::ranges::view_base { - int start = 0; - constexpr explicit View(int start) : start(start) {} - View() noexcept(IsNoexcept) = default; + int start_ = 0; + explicit View() noexcept(IsNoexcept) = default; + constexpr explicit View(int start) : start_(start) {} View(View&&) noexcept(IsNoexcept) = default; View& operator=(View&&) noexcept(IsNoexcept) = default; - constexpr friend int* begin(View& view) { return globalBuff + view.start; } - constexpr friend int* begin(View const& view) { return globalBuff + view.start; } + constexpr friend int* begin(View& view) { return globalBuff + view.start_; } + constexpr friend int* begin(View const& view) { return globalBuff + view.start_; } constexpr friend int* end(View&) { return globalBuff + 8; } constexpr friend int* end(View const&) { return globalBuff + 8; } }; @@ -37,13 +37,13 @@ static_assert(std::ranges::view>); template struct CopyableView : std::ranges::view_base { - int start = 0; - CopyableView() noexcept(IsNoexcept) = default; + int start_ = 0; + explicit CopyableView() noexcept(IsNoexcept) = default; CopyableView(CopyableView const&) noexcept(IsNoexcept) = default; CopyableView& operator=(CopyableView const&) noexcept(IsNoexcept) = default; - constexpr explicit CopyableView(int start) noexcept : start(start) {} - constexpr friend int* begin(CopyableView& view) { return globalBuff + view.start; } - constexpr friend int* begin(CopyableView const& view) { return globalBuff + view.start; } + constexpr explicit CopyableView(int start) noexcept : start_(start) {} + constexpr friend int* begin(CopyableView& view) { return globalBuff + view.start_; } + constexpr friend int* begin(CopyableView const& view) { return globalBuff + view.start_; } constexpr friend int* end(CopyableView&) { return globalBuff + 8; } constexpr friend int* end(CopyableView const&) { return globalBuff + 8; } }; @@ -51,23 +51,22 @@ static_assert(std::ranges::view>); static_assert(std::ranges::view>); struct Range { - int start = 0; - constexpr explicit Range(int start) noexcept : start(start) {} - constexpr friend int* begin(Range const& range) { return globalBuff + range.start; } + int start_; + constexpr explicit Range(int start) noexcept : start_(start) {} + constexpr friend int* begin(Range const& range) { return globalBuff + range.start_; } + constexpr friend int* begin(Range& range) { return globalBuff + range.start_; } constexpr friend int* end(Range const&) { return globalBuff + 8; } - constexpr friend int* begin(Range& range) { return globalBuff + range.start; } constexpr friend int* end(Range&) { return globalBuff + 8; } }; struct BorrowableRange { - int start = 0; - constexpr explicit BorrowableRange(int start) noexcept : start(start) {} - constexpr friend int* begin(BorrowableRange const& range) { return globalBuff + range.start; } + int start_; + constexpr explicit BorrowableRange(int start) noexcept : start_(start) {} + constexpr friend int* begin(BorrowableRange const& range) { return globalBuff + range.start_; } + constexpr friend int* begin(BorrowableRange& range) { return globalBuff + range.start_; } constexpr friend int* end(BorrowableRange const&) { return globalBuff + 8; } - constexpr friend int* begin(BorrowableRange& range) { return globalBuff + range.start; } constexpr friend int* end(BorrowableRange&) { return globalBuff + 8; } }; - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; @@ -81,8 +80,6 @@ struct RandomAccessRange { constexpr random_access_iterator begin() { return random_access_iterator{globalBuff}; } constexpr sentinel end() { return {}; } }; - - template<> inline constexpr bool std::ranges::enable_borrowed_range = true; diff --git a/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h b/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h index 95326dbaacd1..554966ef3dc7 100644 --- a/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h +++ b/libcxx/test/std/ranges/range.utility/range.subrange/subrange_test_types.h @@ -135,7 +135,7 @@ struct ConditionallyConvertibleBase { constexpr int *base() const { return base_; } - friend bool operator==(const self&, const self&); + friend bool operator==(const self&, const self&) = default; reference operator*() const; pointer operator->() const; diff --git a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp index 5e5cf707fe24..61cffe112d8a 100644 --- a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp +++ b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp @@ -43,20 +43,16 @@ struct InputRange : std::ranges::view_interface { }; struct NotSizedSentinel { - using I = int*; - using value_type = std::iter_value_t; - using difference_type = std::iter_difference_t; + using value_type = int; + using difference_type = std::ptrdiff_t; using iterator_concept = std::forward_iterator_tag; - NotSizedSentinel() = default; - explicit constexpr NotSizedSentinel(I); - - constexpr int &operator*() const { return *value; }; + explicit NotSizedSentinel() = default; + explicit NotSizedSentinel(int*); + int& operator*() const; NotSizedSentinel& operator++(); NotSizedSentinel operator++(int); bool operator==(NotSizedSentinel const&) const; - - int *value; }; static_assert(std::forward_iterator); @@ -127,13 +123,13 @@ struct BoolConvertibleComparison : std::ranges::view_interface