|
| 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 | + |
| 10 | +// <iterator> |
| 11 | + |
| 12 | +// __bounded_iter<_Iter> |
| 13 | +// __static_bounded_iter<_Iter> |
| 14 | +// __wrap_iter<_Iter> |
| 15 | + |
| 16 | +// Verify that libc++-wrapped iterators do not permit slicing conversion or construction. |
| 17 | + |
| 18 | +#include <array> |
| 19 | +#include <span> |
| 20 | +#include <type_traits> |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +#include "test_macros.h" |
| 24 | + |
| 25 | +struct Base {}; |
| 26 | +struct Derived : Base {}; |
| 27 | + |
| 28 | +template <class B, class D, bool = std::is_pointer<typename std::array<B, 1>::iterator>::value> |
| 29 | +struct test_array_helper : std::true_type { |
| 30 | + typedef typename std::array<B, 1>::iterator BaseIter; |
| 31 | + typedef typename std::array<D, 1>::iterator DerivedIter; |
| 32 | + typedef typename std::array<B, 1>::const_iterator BaseConstIter; |
| 33 | + typedef typename std::array<D, 1>::const_iterator DerivedConstIter; |
| 34 | + |
| 35 | + static_assert(!std::is_convertible<DerivedIter, BaseIter>::value, ""); |
| 36 | + static_assert(!std::is_convertible<DerivedIter, BaseConstIter>::value, ""); |
| 37 | + static_assert(!std::is_convertible<DerivedConstIter, BaseConstIter>::value, ""); |
| 38 | + static_assert(!std::is_constructible<BaseIter, DerivedIter>::value, ""); |
| 39 | + static_assert(!std::is_constructible<BaseConstIter, DerivedIter>::value, ""); |
| 40 | + static_assert(!std::is_constructible<BaseConstIter, DerivedConstIter>::value, ""); |
| 41 | +}; |
| 42 | + |
| 43 | +template <class B, class D> |
| 44 | +struct test_array_helper<B, D, true> : std::true_type {}; |
| 45 | + |
| 46 | +static_assert(test_array_helper<Base, Derived>::value, ""); |
| 47 | + |
| 48 | +static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::iterator>::value, ""); |
| 49 | +static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::const_iterator>::value, ""); |
| 50 | +static_assert(!std::is_convertible<std::vector<Derived>::const_iterator, std::vector<Base>::const_iterator>::value, ""); |
| 51 | +static_assert(!std::is_constructible<std::vector<Base>::iterator, std::vector<Derived>::iterator>::value, ""); |
| 52 | +static_assert(!std::is_constructible<std::vector<Base>::const_iterator, std::vector<Derived>::iterator>::value, ""); |
| 53 | +static_assert(!std::is_constructible<std::vector<Base>::const_iterator, std::vector<Derived>::const_iterator>::value, |
| 54 | + ""); |
| 55 | + |
| 56 | +#if TEST_STD_VER >= 20 |
| 57 | +static_assert(!std::is_convertible_v<std::span<Derived>::iterator, std::span<Base>::iterator>); |
| 58 | +static_assert(!std::is_convertible_v<std::span<Derived>::iterator, std::span<const Base>::iterator>); |
| 59 | +static_assert(!std::is_convertible_v<std::span<const Derived>::iterator, std::span<Base>::iterator>); |
| 60 | +static_assert(!std::is_constructible_v<std::span<Base>::iterator, std::span<Derived>::iterator>); |
| 61 | +static_assert(!std::is_constructible_v<std::span<Base>::iterator, std::span<const Derived>::iterator>); |
| 62 | +static_assert(!std::is_constructible_v<std::span<const Base>::iterator, std::span<const Derived>::iterator>); |
| 63 | +#endif |
0 commit comments