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 // REQUIRES: has-unix-headers
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // UNSUPPORTED: libcpp-hardening-mode=none
12 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
13 
14 #include <iterator>
15 
16 #include "check_assertion.h"
17 #include "test_iterators.h"
18 
main(int,char **)19 int main(int, char**) {
20   using Iter = std::counted_iterator<int*>;
21   int a[]    = {1, 2, 3};
22   Iter valid_i(a, 1);
23 
24   {
25     Iter i;
26 
27     TEST_LIBCPP_ASSERT_FAILURE(*i, "Iterator is equal to or past end.");
28     TEST_LIBCPP_ASSERT_FAILURE(i[999], "Subscript argument must be less than size.");
29     TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_move(i), "Iterator must not be past end of range.");
30     TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_swap(i, valid_i), "Iterators must not be past end of range.");
31     TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_swap(valid_i, i), "Iterators must not be past end of range.");
32     std::ranges::iter_swap(valid_i, valid_i); // Ok
33   }
34 
35   { // Check the `const` overload of `operator*`.
36     const Iter i;
37 
38     TEST_LIBCPP_ASSERT_FAILURE(*i, "Iterator is equal to or past end.");
39   }
40 
41   return 0;
42 }
43