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 --- 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 --- 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 @@ 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 @@ 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 --- 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 @@ -152,9 +152,11 @@ 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: + constexpr const int *begin() const { return nullptr; } }; struct BeginFunctionReturnsEmptyPtr { @@ -182,7 +184,7 @@ 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); @@ -194,16 +196,15 @@ static_assert(!std::is_invocable_v); struct BeginFunctionReturnsPtrConvertible { - friend constexpr PtrConvertible begin(BeginFunctionReturnsPtrConvertible const&); + friend PtrConvertible begin(BeginFunctionReturnsPtrConvertible const&); }; static_assert(!std::is_invocable_v); constexpr bool testBeginFunction() { - const BeginFunction a{}; + BeginFunction a{}; assert(std::ranges::begin(a) == &a.x); - BeginFunction aa{}; - assert(std::ranges::cbegin(aa) == &aa.x); + assert(std::ranges::cbegin(a) == &a.x); BeginFunctionByValue b; assert(std::ranges::begin(b) == &globalBuff[1]); @@ -211,21 +212,23 @@ BeginFunctionEnabledBorrowing c; assert(std::ranges::begin(std::move(c)) == &globalBuff[2]); + assert(std::ranges::cbegin(std::move(c)) == &globalBuff[2]); + + const BeginFunctionEnabledBorrowing cc; + assert(std::ranges::begin(std::move(cc)) == &globalBuff[2]); + assert(std::ranges::cbegin(std::move(cc)) == &globalBuff[2]); - const BeginFunctionReturnsEmptyPtr d{}; + BeginFunctionReturnsEmptyPtr d{}; assert(std::ranges::begin(d) == &d.x); - BeginFunctionReturnsEmptyPtr dd{}; - assert(std::ranges::cbegin(dd) == &dd.x); + assert(std::ranges::cbegin(d) == &d.x); - const BeginFunctionWithDataMember e{}; + BeginFunctionWithDataMember e{}; assert(std::ranges::begin(e) == &e.x); - BeginFunctionWithDataMember ee{}; - assert(std::ranges::cbegin(ee) == &ee.x); + assert(std::ranges::cbegin(e) == &e.x); - const BeginFunctionWithPrivateBeginMember f{}; + BeginFunctionWithPrivateBeginMember f{}; assert(std::ranges::begin(f) == &f.y); - BeginFunctionWithPrivateBeginMember ff{}; - assert(std::ranges::cbegin(ff) == &ff.y); + assert(std::ranges::cbegin(f) == &f.y); return true; } @@ -243,9 +246,9 @@ }; ASSERT_NOEXCEPT(std::ranges::begin(std::declval())); ASSERT_NOEXCEPT(std::ranges::begin(std::declval&>())); -ASSERT_NOT_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_NOT_NOEXCEPT(std::ranges::begin(std::declval>&>())); int main(int, char**) { 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 --- 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 @@ 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 --- 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 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 SentinelType { - int *base; + int *base_; SentinelType() = default; - explicit constexpr SentinelType(int *base) : base(base) {} - friend constexpr ResultType operator==(ForwardIter const& iter, SentinelType const& sent) noexcept { return {iter.base() == sent.base}; } - friend constexpr ResultType operator==(SentinelType const& sent, ForwardIter const& iter) noexcept { return {iter.base() == sent.base}; } - friend constexpr ResultType operator!=(ForwardIter const& iter, SentinelType const& sent) noexcept { return {iter.base() != sent.base}; } - friend constexpr ResultType operator!=(SentinelType const& sent, ForwardIter const& iter) noexcept { return {iter.base() != sent.base}; } + explicit constexpr SentinelType(int *base) : base_(base) {} + friend constexpr ResultType operator==(ForwardIter const& iter, SentinelType const& sent) noexcept { return {iter.base() == sent.base_}; } + friend constexpr ResultType operator==(SentinelType const& sent, ForwardIter const& iter) noexcept { return {iter.base() == sent.base_}; } + friend constexpr ResultType operator!=(ForwardIter const& iter, SentinelType const& sent) noexcept { return {iter.base() != sent.base_}; } + friend constexpr ResultType operator!=(SentinelType const& sent, ForwardIter const& iter) noexcept { return {iter.base() != sent.base_}; } }; int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7}; diff --git a/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp b/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.ops/copy.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// XFAIL: gcc-10 +// XFAIL: gcc-10, gcc-11 // GCC's __builtin_strlen isn't constexpr yet // UNSUPPORTED: LIBCXX-DEBUG-FIXME