Skip to content

Commit 0edc92e

Browse files
committed
[libc++] LWG3738 Validates a missing precondition.
No real changes were needed, but add an assert for the pre-condition. This implements: - 3738 Missing preconditions for take_view constructor Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D140568
1 parent 83c1816 commit 0edc92e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

libcxx/docs/Status/Cxx2bIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"`3732 <https://wg21.link/LWG3732>`__","``prepend_range`` and ``append_range`` can't be amortized constant time", "November 2022","|Nothing to do|","","|ranges|"
204204
"`3736 <https://wg21.link/LWG3736>`__","``move_iterator`` missing ``disable_sized_sentinel_for`` specialization", "November 2022","","","|ranges|"
205205
"`3737 <https://wg21.link/LWG3737>`__","``take_view::sentinel`` should provide ``operator-``", "November 2022","","","|ranges|"
206-
"`3738 <https://wg21.link/LWG3738>`__","Missing preconditions for ``take_view`` constructor", "November 2022","","","|ranges|"
206+
"`3738 <https://wg21.link/LWG3738>`__","Missing preconditions for ``take_view`` constructor", "November 2022","|Complete|","16.0","|ranges|"
207207
"`3743 <https://wg21.link/LWG3743>`__","``ranges::to``'s reserve may be ill-formed", "November 2022","","","|ranges|"
208208
"`3745 <https://wg21.link/LWG3745>`__","``std::atomic_wait`` and its friends lack ``noexcept``", "November 2022","|Complete|","16.0",""
209209
"`3746 <https://wg21.link/LWG3746>`__","``optional``'s spaceship with ``U`` with a type derived from optional causes infinite constraint meta-recursion", "November 2022","","","|spaceship|"

libcxx/include/__ranges/take_view.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <__algorithm/min.h>
1414
#include <__algorithm/ranges_min.h>
15+
#include <__assert>
1516
#include <__concepts/constructible.h>
1617
#include <__concepts/convertible_to.h>
1718
#include <__config>
@@ -63,9 +64,10 @@ class take_view : public view_interface<take_view<_View>> {
6364
_LIBCPP_HIDE_FROM_ABI
6465
take_view() requires default_initializable<_View> = default;
6566

66-
_LIBCPP_HIDE_FROM_ABI
67-
constexpr take_view(_View __base, range_difference_t<_View> __count)
68-
: __base_(std::move(__base)), __count_(__count) {}
67+
_LIBCPP_HIDE_FROM_ABI constexpr take_view(_View __base, range_difference_t<_View> __count)
68+
: __base_(std::move(__base)), __count_(__count) {
69+
_LIBCPP_ASSERT(__count >= 0, "count has to be greater than or equal to zero");
70+
}
6971

7072
_LIBCPP_HIDE_FROM_ABI
7173
constexpr _View base() const& requires copy_constructible<_View> { return __base_; }

0 commit comments

Comments
 (0)