File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4747// pointer, it is undefined at the language level (see [expr.add]). If
4848// bounded iterators exhibited this undefined behavior, we risk compiler
4949// optimizations deleting non-redundant bounds checks.
50- template <class _Iterator , class = __enable_if_t < __libcpp_is_contiguous_iterator<_Iterator>::value > >
50+ template <class _Iterator >
5151struct __bounded_iter {
52+ static_assert (__libcpp_is_contiguous_iterator<_Iterator>::value,
53+ " Only contiguous iterators can be adapted by __bounded_iter." );
54+
5255 using value_type = typename iterator_traits<_Iterator>::value_type;
5356 using difference_type = typename iterator_traits<_Iterator>::difference_type;
5457 using pointer = typename iterator_traits<_Iterator>::pointer;
@@ -247,7 +250,7 @@ struct __bounded_iter {
247250private:
248251 template <class >
249252 friend struct pointer_traits ;
250- template <class , class >
253+ template <class >
251254 friend struct __bounded_iter ;
252255 _Iterator __current_; // current iterator
253256 _Iterator __begin_, __end_; // valid range represented as [begin, end]
Original file line number Diff line number Diff line change 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+
14+ // Verify that __bounded_iter does not accept non-contiguous iterators as determined by __libcpp_is_contiguous_iterator.
15+ // static_assert should be used, see https://github.com/llvm/llvm-project/issues/115002.
16+ // __wrap_iter cannot be so handled because it may directly wrap user-defined fancy pointers in libc++'s vector.
17+
18+ #include < deque>
19+ #include < vector>
20+
21+ // expected-error-re@*:* {{static assertion failed due to requirement {{.*}}Only contiguous iterators can be adapted by __bounded_iter.}}
22+ std::__bounded_iter<std::deque<int >::iterator> bit;
You can’t perform that action at this time.
0 commit comments