diff --git a/libcxx/include/span b/libcxx/include/span --- a/libcxx/include/span +++ b/libcxx/include/span @@ -39,7 +39,7 @@ // constants and types using element_type = ElementType; using value_type = remove_cv_t; - using index_type = size_t; + using size_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; using const_pointer = const element_type*; @@ -49,11 +49,11 @@ using const_iterator = implementation-defined; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - static constexpr index_type extent = Extent; + static constexpr size_type extent = Extent; // [span.cons], span constructors, copy, assignment, and destructor constexpr span() noexcept; - constexpr span(pointer ptr, index_type count); + constexpr span(pointer ptr, size_type count); constexpr span(pointer firstElem, pointer lastElem); template constexpr span(element_type (&arr)[N]) noexcept; @@ -79,17 +79,17 @@ template constexpr span subspan() const; - constexpr span first(index_type count) const; - constexpr span last(index_type count) const; - constexpr span subspan(index_type offset, index_type count = dynamic_extent) const; + constexpr span first(size_type count) const; + constexpr span last(size_type count) const; + constexpr span subspan(size_type offset, size_type count = dynamic_extent) const; // [span.obs], span observers - constexpr index_type size() const noexcept; - constexpr index_type size_bytes() const noexcept; + constexpr size_type size() const noexcept; + constexpr size_type size_bytes() const noexcept; constexpr bool empty() const noexcept; // [span.elem], span element access - constexpr reference operator[](index_type idx) const; + constexpr reference operator[](size_type idx) const; constexpr reference front() const; constexpr reference back() const; constexpr pointer data() const noexcept; @@ -106,7 +106,7 @@ private: pointer data_; // exposition only - index_type size_; // exposition only + size_type size_; // exposition only }; template @@ -195,7 +195,7 @@ // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = size_t; + using size_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; using const_pointer = const _Tp *; @@ -206,16 +206,16 @@ using reverse_iterator = _VSTD::reverse_iterator; using const_reverse_iterator = _VSTD::reverse_iterator; - static constexpr index_type extent = _Extent; + static constexpr size_type extent = _Extent; // [span.cons], span constructors, copy, assignment, and destructor - _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} - { static_assert(_Extent == 0, "Can't default construct a statically sized span with size > 0"); } + template = nullptr> + _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {} constexpr span (const span&) noexcept = default; constexpr span& operator=(const span&) noexcept = default; - _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr} + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr} { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); } _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f} { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); } @@ -260,14 +260,14 @@ } _LIBCPP_INLINE_VISIBILITY - constexpr span first(index_type __count) const noexcept + constexpr span first(size_type __count) const noexcept { _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY - constexpr span last(index_type __count) const noexcept + constexpr span last(size_type __count) const noexcept { _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; @@ -279,41 +279,42 @@ -> span { static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); + static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } _LIBCPP_INLINE_VISIBILITY constexpr span - subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept { _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return _Extent; } - _LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept + _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept { - _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span[] index out of bounds"); + _LIBCPP_ASSERT(__idx < size(), "span[] index out of bounds"); return __data[__idx]; } _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept { - static_assert(_Extent > 0, "span[].front() on empty span"); + _LIBCPP_ASSERT(!empty(), "span::front() on empty span"); return __data[0]; } _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept { - static_assert(_Extent > 0, "span[].back() on empty span"); + _LIBCPP_ASSERT(!empty(), "span::back() on empty span"); return __data[size()-1]; } @@ -356,7 +357,7 @@ // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = size_t; + using size_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; using const_pointer = const _Tp *; @@ -367,7 +368,7 @@ using reverse_iterator = _VSTD::reverse_iterator; using const_reverse_iterator = _VSTD::reverse_iterator; - static constexpr index_type extent = dynamic_extent; + static constexpr size_type extent = dynamic_extent; // [span.cons], span constructors, copy, assignment, and destructor _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {} @@ -375,7 +376,7 @@ constexpr span (const span&) noexcept = default; constexpr span& operator=(const span&) noexcept = default; - _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr}, __size{__count} {} + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}, __size{__count} {} _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast(distance(__f, __l))} {} template @@ -394,13 +395,13 @@ _LIBCPP_INLINE_VISIBILITY constexpr span( _Container& __c, enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} + : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} template _LIBCPP_INLINE_VISIBILITY constexpr span(const _Container& __c, enable_if_t<__is_span_compatible_container::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} + : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} template @@ -430,14 +431,14 @@ } _LIBCPP_INLINE_VISIBILITY - constexpr span first(index_type __count) const noexcept + constexpr span first(size_type __count) const noexcept { _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY - constexpr span last (index_type __count) const noexcept + constexpr span last (size_type __count) const noexcept { _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; @@ -445,44 +446,44 @@ template _LIBCPP_INLINE_VISIBILITY - constexpr span<_Tp, dynamic_extent> subspan() const noexcept + constexpr span subspan() const noexcept { _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); - _LIBCPP_ASSERT(_Count == dynamic_extent || _Offset + _Count <= size(), "Count out of range in span::subspan()"); + _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } constexpr span _LIBCPP_INLINE_VISIBILITY - subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept { _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return __size; } - _LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return __size * sizeof(element_type); } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; } + _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); } _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept + _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept { - _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span[] index out of bounds"); + _LIBCPP_ASSERT(__idx < size(), "span::operator[] index out of bounds"); return __data[__idx]; } _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept { - _LIBCPP_ASSERT(!empty(), "span[].front() on empty span"); + _LIBCPP_ASSERT(!empty(), "span::front() on empty span"); return __data[0]; } _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept { - _LIBCPP_ASSERT(!empty(), "span[].back() on empty span"); + _LIBCPP_ASSERT(!empty(), "span::back() on empty span"); return __data[size()-1]; } @@ -505,7 +506,7 @@ __data = __other.__data; __other.__data = __p; - index_type __sz = __size; + size_type __sz = __size; __size = __other.__size; __other.__size = __sz; } @@ -518,7 +519,7 @@ private: pointer __data; - index_type __size; + size_type __size; }; // tuple interface diff --git a/libcxx/test/std/containers/views/span.cons/assign.pass.cpp b/libcxx/test/std/containers/views/span.cons/assign.pass.cpp --- a/libcxx/test/std/containers/views/span.cons/assign.pass.cpp +++ b/libcxx/test/std/containers/views/span.cons/assign.pass.cpp @@ -43,11 +43,11 @@ // constexpr dynamically sized assignment { // On systems where 'ptrdiff_t' is a synonym for 'int', -// the call span(ptr, 0) selects the (pointer, index_type) constructor. +// the call span(ptr, 0) selects the (pointer, size_type) constructor. // On systems where 'ptrdiff_t' is NOT a synonym for 'int', // it is ambiguous, because of 0 also being convertible to a null pointer // and so the compiler can't choose between: -// span(pointer, index_type) +// span(pointer, size_type) // and span(pointer, pointer) // We cast zero to std::ptrdiff_t to remove that ambiguity. // Example: diff --git a/libcxx/test/std/containers/views/span.cons/default.fail.cpp b/libcxx/test/std/containers/views/span.cons/default.fail.cpp --- a/libcxx/test/std/containers/views/span.cons/default.fail.cpp +++ b/libcxx/test/std/containers/views/span.cons/default.fail.cpp @@ -13,7 +13,7 @@ // constexpr span() noexcept; // // Remarks: This constructor shall not participate in overload resolution -// unless Extent <= 0 is true. +// unless Extent == 0 || Extent == dynamic_extent is true. #include @@ -24,10 +24,7 @@ int main(int, char**) { - std::span s; // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Can't default construct a statically sized span with size > 0"}} - -// TODO: This is what I want: -// eXpected-error {{no matching constructor for initialization of 'std::span'}} + std::span s; // expected-error {{no matching constructor for initialization of 'std::span'}} return 0; } diff --git a/libcxx/test/std/containers/views/span.cons/ptr_len.fail.cpp b/libcxx/test/std/containers/views/span.cons/ptr_len.fail.cpp --- a/libcxx/test/std/containers/views/span.cons/ptr_len.fail.cpp +++ b/libcxx/test/std/containers/views/span.cons/ptr_len.fail.cpp @@ -10,7 +10,7 @@ // -// constexpr span(pointer ptr, index_type count); +// constexpr span(pointer ptr, size_type count); // Requires: [ptr, ptr + count) shall be a valid range. // If extent is not equal to dynamic_extent, then count shall be equal to extent. // diff --git a/libcxx/test/std/containers/views/span.cons/ptr_len.pass.cpp b/libcxx/test/std/containers/views/span.cons/ptr_len.pass.cpp --- a/libcxx/test/std/containers/views/span.cons/ptr_len.pass.cpp +++ b/libcxx/test/std/containers/views/span.cons/ptr_len.pass.cpp @@ -10,7 +10,7 @@ // -// constexpr span(pointer ptr, index_type count); +// constexpr span(pointer ptr, size_type count); // Requires: [ptr, ptr + count) shall be a valid range. // If extent is not equal to dynamic_extent, then count shall be equal to extent. // diff --git a/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp b/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp --- a/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp +++ b/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp @@ -10,8 +10,8 @@ // -// constexpr reference operator[](index_type idx) const; -// constexpr reference operator()(index_type idx) const; +// constexpr reference operator[](size_type idx) const; +// constexpr reference operator()(size_type idx) const; // diff --git a/libcxx/test/std/containers/views/span.iterators/rbegin.pass.cpp b/libcxx/test/std/containers/views/span.iterators/rbegin.pass.cpp --- a/libcxx/test/std/containers/views/span.iterators/rbegin.pass.cpp +++ b/libcxx/test/std/containers/views/span.iterators/rbegin.pass.cpp @@ -31,7 +31,7 @@ } else { - const typename Span::index_type last = s.size() - 1; + const typename Span::size_type last = s.size() - 1; ret = ret && ( *b == s[last]); ret = ret && ( &*b == &s[last]); ret = ret && ( *cb == s[last]); @@ -54,7 +54,7 @@ } else { - const typename Span::index_type last = s.size() - 1; + const typename Span::size_type last = s.size() - 1; assert( *b == s[last]); assert( &*b == &s[last]); assert( *cb == s[last]); diff --git a/libcxx/test/std/containers/views/span.obs/size.pass.cpp b/libcxx/test/std/containers/views/span.obs/size.pass.cpp --- a/libcxx/test/std/containers/views/span.obs/size.pass.cpp +++ b/libcxx/test/std/containers/views/span.obs/size.pass.cpp @@ -10,7 +10,7 @@ // -// constexpr index_type size() const noexcept; +// constexpr size_type size() const noexcept; // diff --git a/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp b/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp --- a/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp @@ -10,7 +10,7 @@ // -// constexpr index_type size_bytes() const noexcept; +// constexpr size_type size_bytes() const noexcept; // // Effects: Equivalent to: return size() * sizeof(element_type); diff --git a/libcxx/test/std/containers/views/span.sub/first.fail.cpp b/libcxx/test/std/containers/views/span.sub/first.fail.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/views/span.sub/first.fail.cpp @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===------------------------------ span ---------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 + +// + +// template +// constexpr span first() const; +// +// constexpr span first(size_type count) const; +// +// Requires: 0 <= Count && Count <= size(). + +#include + +#include "test_macros.h" + +constexpr int carr[] = {1, 2, 3, 4}; + +int main(int, char**) { + std::span sp(carr); + + // Count too large + { + [[maybe_unused]] auto s1 = sp.first<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::first()"}} + } + + // Count numeric_limits + { + [[maybe_unused]] auto s1 = sp.first(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::first()"}} + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/span.sub/first.pass.cpp b/libcxx/test/std/containers/views/span.sub/first.pass.cpp --- a/libcxx/test/std/containers/views/span.sub/first.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/first.pass.cpp @@ -13,9 +13,9 @@ // template // constexpr span first() const; // -// constexpr span first(index_type count) const; +// constexpr span first(size_type count) const; // -// Requires: 0 <= Count && Count <= size(). +// Requires: Count <= size(). #include diff --git a/libcxx/test/std/containers/views/span.sub/last.fail.cpp b/libcxx/test/std/containers/views/span.sub/last.fail.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/views/span.sub/last.fail.cpp @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===------------------------------ span ---------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 + +// + +// template +// constexpr span last() const; +// +// constexpr span last(size_type count) const; +// +// Requires: Count <= size(). + +#include + +#include "test_macros.h" + +constexpr int carr[] = {1, 2, 3, 4}; + +int main(int, char**) { + std::span sp(carr); + + // Count too large + { + [[maybe_unused]] auto s1 = sp.last<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}} + } + + // Count numeric_limits + { + [[maybe_unused]] auto s1 = sp.last(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}} + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/span.sub/last.pass.cpp b/libcxx/test/std/containers/views/span.sub/last.pass.cpp --- a/libcxx/test/std/containers/views/span.sub/last.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/last.pass.cpp @@ -13,9 +13,9 @@ // template // constexpr span last() const; // -// constexpr span last(index_type count) const; +// constexpr span last(size_type count) const; // -// Requires: 0 <= Count && Count <= size(). +// Requires: Count <= size(). #include diff --git a/libcxx/test/std/containers/views/span.sub/subspan.fail.cpp b/libcxx/test/std/containers/views/span.sub/subspan.fail.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/views/span.sub/subspan.fail.cpp @@ -0,0 +1,52 @@ +// -*- C++ -*- +//===------------------------------ span ---------------------------------===// +// +// 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++98, c++03, c++11, c++14, c++17 + +// + +// template +// constexpr span subspan() const; +// +// constexpr span subspan( +// size_type offset, size_type count = dynamic_extent) const; +// +// Requires: offset <= size() && +// (count == dynamic_extent || count <= size() - offset) + +#include + +#include "test_macros.h" + +constexpr int carr[] = {1, 2, 3, 4}; + +int main(int, char**) { + std::span sp(carr); + + // Offset too large templatized + { + [[maybe_unused]] auto s1 = sp.subspan<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset out of range in span::subspan()"}} + } + + // Count too large templatized + { + [[maybe_unused]] auto s1 = sp.subspan<0, 5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}} + } + + // Offset + Count too large templatized + { + [[maybe_unused]] auto s1 = sp.subspan<2, 3>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}} + } + + // Offset + Count overflow templatized + { + [[maybe_unused]] auto s1 = sp.subspan<3, std::size_t(-2)>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}}, expected-error-re@span:* {{array is too large{{(.* elements)}}}} + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp --- a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp @@ -14,7 +14,7 @@ // constexpr span subspan() const; // // constexpr span subspan( -// index_type offset, index_type count = dynamic_extent) const; +// size_type offset, size_type count = dynamic_extent) const; // // Requires: (0 <= Offset && Offset <= size()) // && (Count == dynamic_extent || Count >= 0 && Offset + Count <= size()) @@ -37,8 +37,11 @@ using S2 = decltype(s2); ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type); ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type); - static_assert(S1::extent == (Span::extent == std::dynamic_extent ? std::dynamic_extent : Count), ""); - static_assert(S2::extent == std::dynamic_extent, ""); + static_assert(S1::extent == + ((Count != std::dynamic_extent) ? Count + : ((Span::extent != std::dynamic_extent) ? Span::extent - Offset + : std::dynamic_extent)), ""); + static_assert(S2::extent == std::dynamic_extent, ""); return s1.data() == s2.data() && s1.size() == s2.size() @@ -76,7 +79,10 @@ using S2 = decltype(s2); ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type); ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type); - static_assert(S1::extent == (Span::extent == std::dynamic_extent ? std::dynamic_extent : Count), ""); + static_assert(S1::extent == + ((Count != std::dynamic_extent) ? Count + : ((Span::extent != std::dynamic_extent) ? Span::extent - Offset + : std::dynamic_extent)), ""); static_assert(S2::extent == std::dynamic_extent, ""); assert(s1.data() == s2.data()); assert(s1.size() == s2.size()); diff --git a/libcxx/test/std/containers/views/types.pass.cpp b/libcxx/test/std/containers/views/types.pass.cpp --- a/libcxx/test/std/containers/views/types.pass.cpp +++ b/libcxx/test/std/containers/views/types.pass.cpp @@ -16,7 +16,7 @@ // // constants and types // using element_type = ElementType; // using value_type = remove_cv_t; -// using index_type = size_t; +// using size_type = size_t; // using difference_type = ptrdiff_t; // using pointer = element_type *; // using reference = element_type &; @@ -27,7 +27,7 @@ // using reverse_iterator = std::reverse_iterator; // using const_reverse_iterator = std::reverse_iterator; // -// static constexpr index_type extent = Extent; +// static constexpr size_type extent = Extent; // #include @@ -68,7 +68,7 @@ { ASSERT_SAME_TYPE(typename S::element_type, ElementType); ASSERT_SAME_TYPE(typename S::value_type, std::remove_cv_t); - ASSERT_SAME_TYPE(typename S::index_type, std::size_t); + ASSERT_SAME_TYPE(typename S::size_type, std::size_t); ASSERT_SAME_TYPE(typename S::difference_type, std::ptrdiff_t); ASSERT_SAME_TYPE(typename S::pointer, ElementType *); ASSERT_SAME_TYPE(typename S::const_pointer, const ElementType *);