[libcxx-commits] [PATCH] D71997: [libcxx] span: Fix incorrect return type of span::subspan

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 11 03:06:08 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG92a1f65f17d7: [libc++] span: Fix incorrect return type of span::subspan (authored by ldionne).

Changed prior to commit:
  https://reviews.llvm.org/D71997?vs=235584&id=243784#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71997/new/

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,7 +37,13 @@
     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 @@
     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());
Index: libcxx/include/span
===================================================================
--- libcxx/include/span
+++ libcxx/include/span
@@ -444,7 +444,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.243784.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200211/7d5e951c/attachment.bin>


More information about the libcxx-commits mailing list