From 8eda3ad29d89317aa25cf2e7aaf8c785b32fc608 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 6 Mar 2019 03:59:44 +0000 Subject: [PATCH] Eradicate all the ptrdiff_ts in span left over from applying P1227. A couple of other minor cleanups. NFC llvm-svn: 355481 --- libcxx/include/span | 81 +++++++++---------- .../containers/views/span.cons/span.fail.cpp | 2 +- .../containers/views/span.cons/span.pass.cpp | 2 +- .../views/span.elem/op_idx.pass.cpp | 4 +- .../views/span.objectrep/as_bytes.pass.cpp | 6 +- .../as_writeable_bytes.fail.cpp | 4 +- .../as_writeable_bytes.pass.cpp | 6 +- .../views/span.obs/size_bytes.pass.cpp | 4 +- .../containers/views/span.sub/first.pass.cpp | 6 +- .../containers/views/span.sub/last.pass.cpp | 6 +- .../views/span.sub/subspan.pass.cpp | 10 +-- .../test/std/containers/views/types.pass.cpp | 2 +- 12 files changed, 66 insertions(+), 67 deletions(-) diff --git a/libcxx/include/span b/libcxx/include/span index 1cb1a1835c3d..c2ed8b176644 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -25,11 +25,11 @@ template // [span.objectrep], views of object representation template span(sizeof(ElementType)) * Extent))> as_bytes(span s) noexcept; + (sizeof(ElementType) * Extent))> as_bytes(span s) noexcept; template span< byte, ((Extent == dynamic_extent) ? dynamic_extent : - (static_cast(sizeof(ElementType)) * Extent))> as_writable_bytes(span s) noexcept; + (sizeof(ElementType) * Extent))> as_writable_bytes(span s) noexcept; namespace std { @@ -207,7 +207,6 @@ public: using const_reverse_iterator = _VSTD::reverse_iterator; static constexpr index_type extent = _Extent; - static_assert (_Extent >= 0, "Can't have a span with an extent < 0"); // [span.cons], span constructors, copy, assignment, and destructor _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} @@ -226,7 +225,7 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span(const array& __arr) noexcept : __data{__arr.data()} {} template - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _Extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -234,7 +233,7 @@ public: : __data{__other.data()} {} template - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, dynamic_extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -245,16 +244,16 @@ public: // ~span() noexcept = default; template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span first() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span first() const noexcept { static_assert(_Count <= _Extent, "Count out of range in span::first()"); return {data(), _Count}; } template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span last() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span last() const noexcept { static_assert(_Count <= _Extent, "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; @@ -263,36 +262,36 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _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 { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } template - inline _LIBCPP_INLINE_VISIBILITY - constexpr auto subspan() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr auto subspan() const noexcept -> span { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); + _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 + __count <= size(), "count + offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } @@ -380,32 +379,32 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast(distance(__f, __l))} {} template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(array& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(array& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(const array& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(const array& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template - inline _LIBCPP_INLINE_VISIBILITY + _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)} {} template - inline _LIBCPP_INLINE_VISIBILITY + _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)} {} template - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _OtherExtent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -415,16 +414,16 @@ public: // ~span() noexcept = default; template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span first() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span first() const noexcept { _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); return {data(), _Count}; } template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span last() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span last() const noexcept { _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; @@ -433,35 +432,35 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _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 { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<_Tp, dynamic_extent> subspan() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<_Tp, dynamic_extent> subspan() const noexcept { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + _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()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } constexpr span - inline _LIBCPP_INLINE_VISIBILITY - subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + _LIBCPP_INLINE_VISIBILITY + subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); + _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 + __count <= size(), "Offset + count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } diff --git a/libcxx/test/std/containers/views/span.cons/span.fail.cpp b/libcxx/test/std/containers/views/span.cons/span.fail.cpp index f559b1fb0c29..c303719fd016 100644 --- a/libcxx/test/std/containers/views/span.cons/span.fail.cpp +++ b/libcxx/test/std/containers/views/span.cons/span.fail.cpp @@ -10,7 +10,7 @@ // -// template +// template // constexpr span(const span& s) noexcept; // // Remarks: This constructor shall not participate in overload resolution unless: diff --git a/libcxx/test/std/containers/views/span.cons/span.pass.cpp b/libcxx/test/std/containers/views/span.cons/span.pass.cpp index 74da3fce894a..62f8b9da11b8 100644 --- a/libcxx/test/std/containers/views/span.cons/span.pass.cpp +++ b/libcxx/test/std/containers/views/span.cons/span.pass.cpp @@ -10,7 +10,7 @@ // -// template +// template // constexpr span(const span& s) noexcept; // // Remarks: This constructor shall not participate in overload resolution unless: 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 index cb63ec9d17b2..893331ad8f12 100644 --- a/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp +++ b/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp @@ -23,7 +23,7 @@ template -constexpr bool testConstexprSpan(Span sp, ptrdiff_t idx) +constexpr bool testConstexprSpan(Span sp, size_t idx) { _LIBCPP_ASSERT(noexcept(sp[idx]), ""); @@ -34,7 +34,7 @@ constexpr bool testConstexprSpan(Span sp, ptrdiff_t idx) template -void testRuntimeSpan(Span sp, ptrdiff_t idx) +void testRuntimeSpan(Span sp, size_t idx) { _LIBCPP_ASSERT(noexcept(sp[idx]), ""); diff --git a/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp b/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp index 12772c42f160..ff1038e0b11c 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp @@ -10,11 +10,11 @@ // -// template +// template // span(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_bytes(span s) noexcept; @@ -36,7 +36,7 @@ void testRuntimeSpan(Span sp) if (sp.extent == std::dynamic_extent) assert(spBytes.extent == std::dynamic_extent); else - assert(spBytes.extent == static_cast(sizeof(typename Span::element_type)) * sp.extent); + assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent); assert((void *) spBytes.data() == (void *) sp.data()); assert(spBytes.size() == sp.size_bytes()); diff --git a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp index 9dadedd75238..388da084ae09 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp @@ -10,11 +10,11 @@ // -// template +// template // span(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_writeable_bytes(span s) noexcept; diff --git a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp index b12500d4ffb1..409f6fa7cd6e 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp @@ -10,11 +10,11 @@ // -// template +// template // span(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_writeable_bytes(span s) noexcept; @@ -36,7 +36,7 @@ void testRuntimeSpan(Span sp) if (sp.extent == std::dynamic_extent) assert(spBytes.extent == std::dynamic_extent); else - assert(spBytes.extent == static_cast(sizeof(typename Span::element_type)) * sp.extent); + assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent); assert(static_cast(spBytes.data()) == static_cast(sp.data())); assert(spBytes.size() == sp.size_bytes()); 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 index 447829d516eb..257956684eaa 100644 --- a/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp @@ -23,7 +23,7 @@ template -constexpr bool testConstexprSpan(Span sp, ptrdiff_t sz) +constexpr bool testConstexprSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size_bytes()); return (size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type); @@ -31,7 +31,7 @@ constexpr bool testConstexprSpan(Span sp, ptrdiff_t sz) template -void testRuntimeSpan(Span sp, ptrdiff_t sz) +void testRuntimeSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size_bytes()); assert((size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type)); diff --git a/libcxx/test/std/containers/views/span.sub/first.pass.cpp b/libcxx/test/std/containers/views/span.sub/first.pass.cpp index f9da9fdc2338..30ab130381cb 100644 --- a/libcxx/test/std/containers/views/span.sub/first.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/first.pass.cpp @@ -10,7 +10,7 @@ // -// template +// template // constexpr span first() const; // // constexpr span first(index_type count) const; @@ -25,7 +25,7 @@ #include "test_macros.h" -template +template constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template first()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) } -template +template void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template first()))); diff --git a/libcxx/test/std/containers/views/span.sub/last.pass.cpp b/libcxx/test/std/containers/views/span.sub/last.pass.cpp index e0a399ff9cd3..2864a7f65e5c 100644 --- a/libcxx/test/std/containers/views/span.sub/last.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/last.pass.cpp @@ -10,7 +10,7 @@ // -// template +// template // constexpr span last() const; // // constexpr span last(index_type count) const; @@ -25,7 +25,7 @@ #include "test_macros.h" -template +template constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template last()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) } -template +template void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template last()))); diff --git a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp index 9cb731093472..f2dbe8408dd4 100644 --- a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp @@ -10,7 +10,7 @@ // -// template +// template // constexpr span subspan() const; // // constexpr span subspan( @@ -26,7 +26,7 @@ #include "test_macros.h" -template +template constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) && std::equal(s1.begin(), s1.end(), sp.begin() + Offset); } -template +template constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan()))); @@ -65,7 +65,7 @@ constexpr bool testConstexprSpan(Span sp) } -template +template void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan()))); @@ -84,7 +84,7 @@ void testRuntimeSpan(Span sp) } -template +template void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan()))); diff --git a/libcxx/test/std/containers/views/types.pass.cpp b/libcxx/test/std/containers/views/types.pass.cpp index 60c365b8938b..787cfdd4e0c4 100644 --- a/libcxx/test/std/containers/views/types.pass.cpp +++ b/libcxx/test/std/containers/views/types.pass.cpp @@ -10,7 +10,7 @@ // -// template +// template // class span { // public: // // constants and types