57 lines · cpp
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-exception6//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// XFAIL: FROZEN-CXX03-HEADERS-FIXME19 20#include <array>21#include <span>22#include <type_traits>23#include <vector>24 25#include "test_macros.h"26 27struct Base {};28struct Derived : Base {};29 30template <class B, class D, bool = std::is_pointer<typename std::array<B, 1>::iterator>::value>31struct test_array_helper : std::true_type {32 typedef typename std::array<B, 1>::iterator BaseIter;33 typedef typename std::array<D, 1>::iterator DerivedIter;34 typedef typename std::array<B, 1>::const_iterator BaseConstIter;35 typedef typename std::array<D, 1>::const_iterator DerivedConstIter;36 37 static_assert(!std::is_convertible<DerivedIter, BaseIter>::value, "");38 static_assert(!std::is_convertible<DerivedIter, BaseConstIter>::value, "");39 static_assert(!std::is_convertible<DerivedConstIter, BaseConstIter>::value, "");40 static_assert(!std::is_constructible<BaseIter, DerivedIter>::value, "");41 static_assert(!std::is_constructible<BaseConstIter, DerivedIter>::value, "");42 static_assert(!std::is_constructible<BaseConstIter, DerivedConstIter>::value, "");43};44 45template <class B, class D>46struct test_array_helper<B, D, true> : std::true_type {};47 48static_assert(test_array_helper<Base, Derived>::value, "");49 50static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::iterator>::value, "");51static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::const_iterator>::value, "");52static_assert(!std::is_convertible<std::vector<Derived>::const_iterator, std::vector<Base>::const_iterator>::value, "");53static_assert(!std::is_constructible<std::vector<Base>::iterator, std::vector<Derived>::iterator>::value, "");54static_assert(!std::is_constructible<std::vector<Base>::const_iterator, std::vector<Derived>::iterator>::value, "");55static_assert(!std::is_constructible<std::vector<Base>::const_iterator, std::vector<Derived>::const_iterator>::value,56 "");57