1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // iterator erase(const_iterator p)
13 #include "asan_testing.h"
20 #include "min_allocator.h"
21 #include "test_macros.h"
23 #ifndef TEST_HAS_NO_EXCEPTIONS
26 Throws(int v
) : v_(v
) {}
27 Throws(const Throws
&rhs
) : v_(rhs
.v_
) { if (sThrows
) throw 1; }
28 Throws( Throws
&&rhs
) : v_(rhs
.v_
) { if (sThrows
) throw 1; }
29 Throws
& operator=(const Throws
&rhs
) { v_
= rhs
.v_
; return *this; }
30 Throws
& operator=( Throws
&&rhs
) { v_
= rhs
.v_
; return *this; }
36 bool Throws::sThrows
= false;
41 make(int size
, int start
= 0 )
43 const int b
= 4096 / sizeof(int);
47 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
52 for (int i
= 0; i
< init
-start
; ++i
)
54 for (int i
= 0; i
< size
; ++i
)
56 for (int i
= 0; i
< start
; ++i
)
65 typedef typename
C::iterator I
;
66 assert(static_cast<std::size_t>(P
) < c1
.size());
67 std::size_t c1_osize
= c1
.size();
68 I i
= c1
.erase(c1
.cbegin() + P
);
69 assert(i
== c1
.begin() + P
);
70 assert(c1
.size() == c1_osize
- 1);
71 assert(static_cast<std::size_t>(std::distance(c1
.begin(), c1
.end())) == c1
.size());
74 for (; j
< P
; ++j
, ++i
)
76 for (++j
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
82 testN(int start
, int N
)
84 int pstep
= std::max(N
/ std::max(std::min(N
, 10), 1), 1);
85 for (int p
= 0; p
< N
; p
+= pstep
)
87 C c1
= make
<C
>(N
, start
);
95 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
96 const int N
= sizeof(rng
)/sizeof(rng
[0]);
97 for (int i
= 0; i
< N
; ++i
)
98 for (int j
= 0; j
< N
; ++j
)
99 testN
<std::deque
<int> >(rng
[i
], rng
[j
]);
101 #if TEST_STD_VER >= 11
103 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
104 const int N
= sizeof(rng
)/sizeof(rng
[0]);
105 for (int i
= 0; i
< N
; ++i
)
106 for (int j
= 0; j
< N
; ++j
)
107 testN
<std::deque
<int, min_allocator
<int>> >(rng
[i
], rng
[j
]);
111 #ifndef TEST_HAS_NO_EXCEPTIONS
113 // Throws: Nothing unless an exception is thrown by the assignment operator of T.
114 // (which includes move assignment)
116 Throws arr
[] = {1, 2, 3};
117 std::deque
<Throws
> v(arr
, arr
+3);
118 Throws::sThrows
= true;
122 assert(v
.size() == 0);
123 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v
));