Skip to content

Commit 637b7f8

Browse files
authored
[libc++] Classify iota_view precondition (#96662)
Fixes #91385
1 parent d0527ab commit 637b7f8

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

libcxx/include/__ranges/iota_view.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <__concepts/semiregular.h>
2323
#include <__concepts/totally_ordered.h>
2424
#include <__config>
25-
#include <__functional/ranges_operations.h>
2625
#include <__iterator/concepts.h>
2726
#include <__iterator/incrementable_traits.h>
2827
#include <__iterator/iterator_traits.h>
@@ -313,8 +312,8 @@ class iota_view : public view_interface<iota_view<_Start, _BoundSentinel>> {
313312
: __value_(std::move(__value)), __bound_sentinel_(std::move(__bound_sentinel)) {
314313
// Validate the precondition if possible.
315314
if constexpr (totally_ordered_with<_Start, _BoundSentinel>) {
316-
_LIBCPP_ASSERT_UNCATEGORIZED(
317-
ranges::less_equal()(__value_, __bound_sentinel_), "Precondition violated: value is greater than bound.");
315+
_LIBCPP_ASSERT_VALID_INPUT_RANGE(
316+
bool(__value_ <= __bound_sentinel_), "iota_view: bound must be reachable from value");
318317
}
319318
}
320319

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
11+
// REQUIRES: has-unix-headers
12+
// UNSUPPORTED: libcpp-hardening-mode=none
13+
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
14+
15+
// Test the precondition check in iota_view(value, bound) that `bound` is reachable from `value`.
16+
17+
#include <ranges>
18+
19+
#include "check_assertion.h"
20+
21+
int main(int, char**) {
22+
{ TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iota_view(5, 0), "iota_view: bound must be reachable from value"); }
23+
{ TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iota_view(10, 5), "iota_view: bound must be reachable from value"); }
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)