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 | // <deque> |
10 | |
11 | // reference operator[](size_type __i); |
12 | // const_reference operator[](size_type __i) const; |
13 | // |
14 | // reference at(size_type __i); |
15 | // const_reference at(size_type __i) const; |
16 | // |
17 | // reference front(); |
18 | // const_reference front() const; |
19 | // |
20 | // reference back(); |
21 | // const_reference back() const; |
22 | // libc++ marks these as 'noexcept' |
23 | |
24 | #include "asan_testing.h" |
25 | #include <deque> |
26 | #include <cassert> |
27 | |
28 | #include "min_allocator.h" |
29 | #include "test_macros.h" |
30 | |
31 | template <class C> |
32 | C |
33 | make(int size, int start = 0 ) |
34 | { |
35 | const int b = 4096 / sizeof(int); |
36 | int init = 0; |
37 | if (start > 0) |
38 | { |
39 | init = (start+1) / b + ((start+1) % b != 0); |
40 | init *= b; |
41 | --init; |
42 | } |
43 | C c(init, 0); |
44 | for (int i = 0; i < init-start; ++i) |
45 | c.pop_back(); |
46 | for (int i = 0; i < size; ++i) |
47 | c.push_back(i); |
48 | for (int i = 0; i < start; ++i) |
49 | c.pop_front(); |
50 | return c; |
51 | } |
52 | |
53 | int main(int, char**) |
54 | { |
55 | { |
56 | typedef std::deque<int> C; |
57 | C c = make<std::deque<int> >(size: 10); |
58 | ASSERT_SAME_TYPE(decltype(c[0]), C::reference); |
59 | LIBCPP_ASSERT_NOEXCEPT( c[0]); |
60 | LIBCPP_ASSERT_NOEXCEPT( c.front()); |
61 | ASSERT_SAME_TYPE(decltype(c.front()), C::reference); |
62 | LIBCPP_ASSERT_NOEXCEPT( c.back()); |
63 | ASSERT_SAME_TYPE(decltype(c.back()), C::reference); |
64 | for (int i = 0; i < 10; ++i) |
65 | assert(c[i] == i); |
66 | for (int i = 0; i < 10; ++i) |
67 | assert(c.at(i) == i); |
68 | assert(c.front() == 0); |
69 | assert(c.back() == 9); |
70 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
71 | } |
72 | { |
73 | typedef std::deque<int> C; |
74 | const C c = make<std::deque<int> >(size: 10); |
75 | ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference); |
76 | LIBCPP_ASSERT_NOEXCEPT( c[0]); |
77 | LIBCPP_ASSERT_NOEXCEPT( c.front()); |
78 | ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference); |
79 | LIBCPP_ASSERT_NOEXCEPT( c.back()); |
80 | ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference); |
81 | for (int i = 0; i < 10; ++i) |
82 | assert(c[i] == i); |
83 | for (int i = 0; i < 10; ++i) |
84 | assert(c.at(i) == i); |
85 | assert(c.front() == 0); |
86 | assert(c.back() == 9); |
87 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
88 | } |
89 | #if TEST_STD_VER >= 11 |
90 | { |
91 | typedef std::deque<int, min_allocator<int>> C; |
92 | C c = make<std::deque<int, min_allocator<int>> >(10); |
93 | ASSERT_SAME_TYPE(decltype(c[0]), C::reference); |
94 | LIBCPP_ASSERT_NOEXCEPT( c[0]); |
95 | LIBCPP_ASSERT_NOEXCEPT( c.front()); |
96 | ASSERT_SAME_TYPE(decltype(c.front()), C::reference); |
97 | LIBCPP_ASSERT_NOEXCEPT( c.back()); |
98 | ASSERT_SAME_TYPE(decltype(c.back()), C::reference); |
99 | for (int i = 0; i < 10; ++i) |
100 | assert(c[i] == i); |
101 | for (int i = 0; i < 10; ++i) |
102 | assert(c.at(i) == i); |
103 | assert(c.front() == 0); |
104 | assert(c.back() == 9); |
105 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
106 | } |
107 | { |
108 | typedef std::deque<int, min_allocator<int>> C; |
109 | const C c = make<std::deque<int, min_allocator<int>> >(10); |
110 | ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference); |
111 | LIBCPP_ASSERT_NOEXCEPT( c[0]); |
112 | LIBCPP_ASSERT_NOEXCEPT( c.front()); |
113 | ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference); |
114 | LIBCPP_ASSERT_NOEXCEPT( c.back()); |
115 | ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference); |
116 | for (int i = 0; i < 10; ++i) |
117 | assert(c[i] == i); |
118 | for (int i = 0; i < 10; ++i) |
119 | assert(c.at(i) == i); |
120 | assert(c.front() == 0); |
121 | assert(c.back() == 9); |
122 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
123 | } |
124 | #endif |
125 | |
126 | return 0; |
127 | } |
128 | |