Skip to content

Commit 88c063c

Browse files
committed
Add iterator fail test
1 parent 3761a57 commit 88c063c

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
// <optional>
10+
11+
// Add to iterator out of bounds.
12+
13+
// REQUIRES: std-at-least-c++26
14+
// UNSUPPORTED: libcpp-hardening-mode=none, libcpp-has-abi-bounded-iterators-in-optional
15+
16+
#include <optional>
17+
18+
#include "check_assertion.h"
19+
20+
int main(int, char**) {
21+
{
22+
std::optional<int> opt(1);
23+
auto i = opt.begin();
24+
25+
TEST_LIBCPP_ASSERT_FAILURE(
26+
i += 2,
27+
"__capacity_aware_iterator::operator+=: Attempting to advance iterator past its container's possible range");
28+
29+
TEST_LIBCPP_ASSERT_FAILURE(
30+
i += -2, "__capacity_aware_iterator::operator+=: Attempting to rewind iterator past its container's start");
31+
32+
TEST_LIBCPP_ASSERT_FAILURE(
33+
i -= 2, "__capacity_aware_iterator::operator-=: Attempting to rewind iterator before its container's start");
34+
35+
TEST_LIBCPP_ASSERT_FAILURE(
36+
i -= -2,
37+
"__capacity_aware_iterator::operator+=: Attempting to advance iterator past its container's possible range");
38+
39+
TEST_LIBCPP_ASSERT_FAILURE(
40+
i[2],
41+
"__capacity_aware_iterator::operator[]: Attempting to index iterator past its container's possible range");
42+
43+
TEST_LIBCPP_ASSERT_FAILURE(
44+
i[-2], "__capacity_aware_iterator::operator[]: Attempting to index iterator before its container's start");
45+
}
46+
}

libcxx/test/libcxx/utilities/optional/optional.iterator/iterator.compile.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// <optional>
1212

13+
// UNSUPPORTED: libcpp-has-abi-bounded-iterators-in-optional
14+
1315
// template <class T> class optional::iterator;
1416
// template <class T> class optional::const_iterator;
1517

libcxx/test/std/utilities/optional/optional.iterator/iterator_compare.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
// <optional>
1212

13-
// template <class T> class optional::iterator;
14-
// template <class T> class optional::const_iterator;
13+
// template <class T> class optional::iterator::operator<=>;
14+
// template <class T> class optional::const_iterator::operator<=>;
1515

1616
#include <cassert>
1717
#include <compare>

libcxx/utils/libcxx/test/features/libcxx_macros.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"_LIBCPP_ABI_VERSION": "libcpp-abi-version",
2626
"_LIBCPP_ABI_BOUNDED_ITERATORS": "libcpp-has-abi-bounded-iterators",
2727
"_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STRING": "libcpp-has-abi-bounded-iterators-in-string",
28+
"_LIBCPP_ABI_BOUNDED_ITERATORS_IN_OPTIONAL": "libcpp-has-abi-bounded-iterators-in-optional",
2829
"_LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR": "libcpp-has-abi-bounded-iterators-in-vector",
2930
"_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY": "libcpp-has-abi-bounded-iterators-in-std-array",
3031
"_LIBCPP_ABI_BOUNDED_UNIQUE_PTR": "libcpp-has-abi-bounded-unique_ptr",

0 commit comments

Comments
 (0)