[libcxx-commits] [PATCH] D108827: [libc++] Add an assertion in the subrange constructors with a size hint

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 30 10:00:52 PDT 2021


ldionne updated this revision to Diff 369475.
ldionne marked an inline comment as done.
ldionne added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108827

Files:
  libcxx/include/__ranges/subrange.h


Index: libcxx/include/__ranges/subrange.h
===================================================================
--- libcxx/include/__ranges/subrange.h
+++ libcxx/include/__ranges/subrange.h
@@ -118,7 +118,11 @@
     constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent,
                        make_unsigned_t<iter_difference_t<_Iter>> __n)
       requires (_Kind == subrange_kind::sized)
-      : _Base(_VSTD::move(__iter), __sent, __n) { }
+      : _Base(_VSTD::move(__iter), __sent, __n)
+    {
+      if constexpr (sized_sentinel_for<_Sent, _Iter> && random_access_iterator<_Iter>)
+        _LIBCPP_ASSERT(ranges::distance(this->__begin_, this->__end_) == __n, "std::ranges::subrange was passed an invalid size hint");
+    }
 
     template<__different_from<subrange> _Range>
       requires borrowed_range<_Range> &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108827.369475.patch
Type: text/x-patch
Size: 849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210830/2f87d799/attachment.bin>


More information about the libcxx-commits mailing list