[libcxx-commits] [libcxx] [libc++] Classify iota_view precondition (PR #96662)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 25 09:02:04 PDT 2024
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/96662
Fixes #91385
>From 7f8329aa3c221368675152d381843d9733458629 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 25 Jun 2024 11:00:44 -0500
Subject: [PATCH] [libc++] Classify iota_view precondition
Fixes #91385
---
libcxx/include/__ranges/iota_view.h | 5 ++--
.../assert.ctor.value.bound.pass.cpp | 26 +++++++++++++++++++
2 files changed, 28 insertions(+), 3 deletions(-)
create mode 100644 libcxx/test/std/ranges/range.factories/range.iota.view/assert.ctor.value.bound.pass.cpp
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;
+}
More information about the libcxx-commits
mailing list