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 make(int size, int start = 0) { |
33 | const int b = 4096 / sizeof(int); |
34 | int init = 0; |
35 | if (start > 0) { |
36 | init = (start + 1) / b + ((start + 1) % b != 0); |
37 | init *= b; |
38 | --init; |
39 | } |
40 | C c(init, 0); |
41 | for (int i = 0; i < init - start; ++i) |
42 | c.pop_back(); |
43 | for (int i = 0; i < size; ++i) |
44 | c.push_back(i); |
45 | for (int i = 0; i < start; ++i) |
46 | c.pop_front(); |
47 | return c; |
48 | } |
49 | |
50 | int main(int, char**) { |
51 | { |
52 | typedef std::deque<int> C; |
53 | C c = make<std::deque<int> >(size: 10); |
54 | ASSERT_SAME_TYPE(decltype(c[0]), C::reference); |
55 | LIBCPP_ASSERT_NOEXCEPT(c[0]); |
56 | LIBCPP_ASSERT_NOEXCEPT(c.front()); |
57 | ASSERT_SAME_TYPE(decltype(c.front()), C::reference); |
58 | LIBCPP_ASSERT_NOEXCEPT(c.back()); |
59 | ASSERT_SAME_TYPE(decltype(c.back()), C::reference); |
60 | for (int i = 0; i < 10; ++i) |
61 | assert(c[i] == i); |
62 | for (int i = 0; i < 10; ++i) |
63 | assert(c.at(i) == i); |
64 | assert(c.front() == 0); |
65 | assert(c.back() == 9); |
66 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
67 | } |
68 | { |
69 | typedef std::deque<int> C; |
70 | const C c = make<std::deque<int> >(size: 10); |
71 | ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference); |
72 | LIBCPP_ASSERT_NOEXCEPT(c[0]); |
73 | LIBCPP_ASSERT_NOEXCEPT(c.front()); |
74 | ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference); |
75 | LIBCPP_ASSERT_NOEXCEPT(c.back()); |
76 | ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference); |
77 | for (int i = 0; i < 10; ++i) |
78 | assert(c[i] == i); |
79 | for (int i = 0; i < 10; ++i) |
80 | assert(c.at(i) == i); |
81 | assert(c.front() == 0); |
82 | assert(c.back() == 9); |
83 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
84 | } |
85 | #if TEST_STD_VER >= 11 |
86 | { |
87 | typedef std::deque<int, min_allocator<int>> C; |
88 | C c = make<std::deque<int, min_allocator<int>> >(10); |
89 | ASSERT_SAME_TYPE(decltype(c[0]), C::reference); |
90 | LIBCPP_ASSERT_NOEXCEPT(c[0]); |
91 | LIBCPP_ASSERT_NOEXCEPT(c.front()); |
92 | ASSERT_SAME_TYPE(decltype(c.front()), C::reference); |
93 | LIBCPP_ASSERT_NOEXCEPT(c.back()); |
94 | ASSERT_SAME_TYPE(decltype(c.back()), C::reference); |
95 | for (int i = 0; i < 10; ++i) |
96 | assert(c[i] == i); |
97 | for (int i = 0; i < 10; ++i) |
98 | assert(c.at(i) == i); |
99 | assert(c.front() == 0); |
100 | assert(c.back() == 9); |
101 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
102 | } |
103 | { |
104 | typedef std::deque<int, min_allocator<int>> C; |
105 | const C c = make<std::deque<int, min_allocator<int>> >(10); |
106 | ASSERT_SAME_TYPE(decltype(c[0]), C::const_reference); |
107 | LIBCPP_ASSERT_NOEXCEPT(c[0]); |
108 | LIBCPP_ASSERT_NOEXCEPT(c.front()); |
109 | ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference); |
110 | LIBCPP_ASSERT_NOEXCEPT(c.back()); |
111 | ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference); |
112 | for (int i = 0; i < 10; ++i) |
113 | assert(c[i] == i); |
114 | for (int i = 0; i < 10; ++i) |
115 | assert(c.at(i) == i); |
116 | assert(c.front() == 0); |
117 | assert(c.back() == 9); |
118 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); |
119 | } |
120 | #endif |
121 | |
122 | return 0; |
123 | } |
124 | |