[libcxx-commits] [libcxx] [libc++] Classify iota_view precondition (PR #96662)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 25 09:02:36 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Louis Dionne (ldionne)
<details>
<summary>Changes</summary>
Fixes #<!-- -->91385
---
Full diff: https://github.com/llvm/llvm-project/pull/96662.diff
2 Files Affected:
- (modified) libcxx/include/__ranges/iota_view.h (+2-3)
- (added) libcxx/test/std/ranges/range.factories/range.iota.view/assert.ctor.value.bound.pass.cpp (+26)
``````````diff
diff --git a/libcxx/include/__ranges/iota_view.h b/libcxx/include/__ranges/iota_view.h
index 9e6f724241ccf..c0f5ed936a66d 100644
--- a/libcxx/include/__ranges/iota_view.h
+++ b/libcxx/include/__ranges/iota_view.h
@@ -22,7 +22,6 @@
#include <__concepts/semiregular.h>
#include <__concepts/totally_ordered.h>
#include <__config>
-#include <__functional/ranges_operations.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/iterator_traits.h>
@@ -313,8 +312,8 @@ class iota_view : public view_interface<iota_view<_Start, _BoundSentinel>> {
: __value_(std::move(__value)), __bound_sentinel_(std::move(__bound_sentinel)) {
// Validate the precondition if possible.
if constexpr (totally_ordered_with<_Start, _BoundSentinel>) {
- _LIBCPP_ASSERT_UNCATEGORIZED(
- ranges::less_equal()(__value_, __bound_sentinel_), "Precondition violated: value is greater than bound.");
+ _LIBCPP_ASSERT_VALID_INPUT_RANGE(
+ bool(__value_ <= __bound_sentinel_), "iota_view: bound must be reachable from value");
}
}
diff --git a/libcxx/test/std/ranges/range.factories/range.iota.view/assert.ctor.value.bound.pass.cpp b/libcxx/test/std/ranges/range.factories/range.iota.view/assert.ctor.value.bound.pass.cpp
new file mode 100644
index 0000000000000..da21a32bf8298
--- /dev/null
+++ b/libcxx/test/std/ranges/range.factories/range.iota.view/assert.ctor.value.bound.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// REQUIRES: has-unix-headers
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+// Test the precondition check in iota_view(value, bound) that `bound` is reachable from `value`.
+
+#include <ranges>
+
+#include "check_assertion.h"
+
+int main(int, char**) {
+ { TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iota_view(5, 0), "iota_view: bound must be reachable from value"); }
+ { TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iota_view(10, 5), "iota_view: bound must be reachable from value"); }
+
+ return 0;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/96662
More information about the libcxx-commits
mailing list