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 // void push_back(const value_type& v);
12 // void pop_back();
13 // void pop_front();
14
15 #include "asan_testing.h"
16 #include <deque>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "min_allocator.h"
21
22 template <class C>
23 C
make(int size,int start=0)24 make(int size, int start = 0 )
25 {
26 const int b = 4096 / sizeof(int);
27 int init = 0;
28 if (start > 0)
29 {
30 init = (start+1) / b + ((start+1) % b != 0);
31 init *= b;
32 --init;
33 }
34 C c(init, 0);
35 for (int i = 0; i < init-start; ++i)
36 c.pop_back();
37 for (int i = 0; i < size; ++i)
38 c.push_back(i);
39 for (int i = 0; i < start; ++i)
40 c.pop_front();
41 return c;
42 }
43
44 template <class C>
test(int size)45 void test(int size)
46 {
47 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
48 const int N = sizeof(rng)/sizeof(rng[0]);
49 for (int j = 0; j < N; ++j)
50 {
51 C c = make<C>(size, rng[j]);
52 typename C::const_iterator it = c.begin();
53 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
54 for (int i = 0; i < size; ++i, ++it)
55 assert(*it == i);
56 }
57 }
58
main(int,char **)59 int main(int, char**)
60 {
61 {
62 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
63 const int N = sizeof(rng)/sizeof(rng[0]);
64 for (int j = 0; j < N; ++j)
65 test<std::deque<int> >(rng[j]);
66 }
67 #if TEST_STD_VER >= 11
68 {
69 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
70 const int N = sizeof(rng)/sizeof(rng[0]);
71 for (int j = 0; j < N; ++j)
72 test<std::deque<int, min_allocator<int>> >(rng[j]);
73 }
74 #endif
75
76 return 0;
77 }
78