[libcxx-commits] [libcxx] 92a1f65 - [libc++] span: Fix incorrect return type of span::subspan
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 11 02:58:57 PST 2020
Author: Louis Dionne
Date: 2020-02-11T11:58:45+01:00
New Revision: 92a1f65f17d7a560c6ad388d9f2e8f1d77f6f04a
URL: https://github.com/llvm/llvm-project/commit/92a1f65f17d7a560c6ad388d9f2e8f1d77f6f04a
DIFF: https://github.com/llvm/llvm-project/commit/92a1f65f17d7a560c6ad388d9f2e8f1d77f6f04a.diff
LOG: [libc++] span: Fix incorrect return type of span::subspan
The extent of the returned span was always std::dynamic_extent, which
is incorrect.
Thanks to Michael Schellenberger Costa for the patch.
Differential Revision: https://reviews.llvm.org/D71997
Added:
Modified:
libcxx/include/span
libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/span b/libcxx/include/span
index f18d00c43928..a5362ca91cf1 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -444,7 +444,7 @@ public:
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()");
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 caa7b564df3e..e46dcc19d97a 100644
--- a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
+++ b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp
@@ -37,7 +37,13 @@ constexpr bool testConstexprSpan(Span sp)
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), "");
+ if constexpr (Count != std::dynamic_extent) {
+ static_assert(S1::extent == Count);
+ } else if constexpr (Span::extent != std::dynamic_extent) {
+ static_assert(S1::extent == Span::extent - Offset);
+ } else {
+ static_assert(S1::extent == std::dynamic_extent);
+ }
static_assert(S2::extent == std::dynamic_extent, "");
return
s1.data() == s2.data()
@@ -76,7 +82,13 @@ void testRuntimeSpan(Span sp)
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), "");
+ if constexpr (Count != std::dynamic_extent) {
+ static_assert(S1::extent == Count);
+ } else if constexpr (Span::extent != std::dynamic_extent) {
+ static_assert(S1::extent == Span::extent - Offset);
+ } else {
+ static_assert(S1::extent == std::dynamic_extent);
+ }
static_assert(S2::extent == std::dynamic_extent, "");
assert(s1.data() == s2.data());
assert(s1.size() == s2.size());
More information about the libcxx-commits
mailing list