[libcxx-commits] [PATCH] D71997: [libcxx] span: Fix incorrect return type of span::subspan
Michael Schellenberger Costa via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 30 05:22:45 PST 2019
miscco created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, ldionne, christof.
Herald added a project: libc++.
The extent of the returned span was incorrect
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71997
Files:
libcxx/include/span
libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
Index: libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
===================================================================
--- libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
+++ libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
@@ -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());
Index: libcxx/include/span
===================================================================
--- libcxx/include/span
+++ libcxx/include/span
@@ -445,7 +445,7 @@
template <size_t _Offset, size_t _Count = dynamic_extent>
_LIBCPP_INLINE_VISIBILITY
- constexpr span<_Tp, dynamic_extent> subspan() const noexcept
+ constexpr span<element_type, _Count> 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()");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71997.235584.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191230/9246a0de/attachment.bin>
More information about the libcxx-commits
mailing list