|
| 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 |
| 11 | +// UNSUPPORTED: libcpp-hardening-mode=unchecked |
| 12 | +// XFAIL: availability-verbose_abort-missing |
| 13 | + |
| 14 | +#include <iterator> |
| 15 | + |
| 16 | +#include "check_assertion.h" |
| 17 | +#include "test_iterators.h" |
| 18 | + |
| 19 | +int main(int, char**) { |
| 20 | + using Iter = std::common_iterator<int*, sentinel_wrapper<int*>>; |
| 21 | + int a[] = {1, 2, 3}; |
| 22 | + sentinel_wrapper<int*> s; |
| 23 | + Iter valid_i = a; |
| 24 | + |
| 25 | + { |
| 26 | + Iter i = s; |
| 27 | + |
| 28 | + TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable common_iterator"); |
| 29 | + |
| 30 | + TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-dereferenceable common_iterator"); |
| 31 | + TEST_LIBCPP_ASSERT_FAILURE(i++, "Attempted to increment a non-dereferenceable common_iterator"); |
| 32 | + |
| 33 | + TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_move(i), "Attempted to iter_move a non-dereferenceable common_iterator"); |
| 34 | + |
| 35 | + TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_swap(i, valid_i), "Attempted to iter_swap a non-dereferenceable common_iterator"); |
| 36 | + TEST_LIBCPP_ASSERT_FAILURE(std::ranges::iter_swap(valid_i, i), "Attempted to iter_swap a non-dereferenceable common_iterator"); |
| 37 | + std::ranges::iter_swap(valid_i, valid_i); // Ok |
| 38 | + } |
| 39 | + |
| 40 | + { // Check the `const` overload of `operator*`. |
| 41 | + const Iter i = s; |
| 42 | + TEST_LIBCPP_ASSERT_FAILURE(*i, "Attempted to dereference a non-dereferenceable common_iterator"); |
| 43 | + } |
| 44 | + |
| 45 | + { // Check `operator->`. |
| 46 | + struct Foo { |
| 47 | + int x = 0; |
| 48 | + }; |
| 49 | + |
| 50 | + std::common_iterator<Foo*, sentinel_wrapper<Foo*>> i = sentinel_wrapper<Foo*>(); |
| 51 | + TEST_LIBCPP_ASSERT_FAILURE(i->x, "Attempted to dereference a non-dereferenceable common_iterator"); |
| 52 | + } |
| 53 | + |
| 54 | + // TODO: check `valueless_by_exception |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
0 commit comments