Skip to content

Commit 4c8fe79

Browse files
committed
Add exception test for element-wise move ctor
1 parent f9daf2c commit 4c8fe79

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libcxx/test/std/containers/sequences/vector/vector.cons/exceptions.pass.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <vector>
1818

1919
#include "count_new.h"
20+
#include "test_allocator.h"
2021
#include "test_iterators.h"
2122

2223
template <class T>
@@ -36,7 +37,9 @@ struct Allocator {
3637
void deallocate(T* ptr, std::size_t n) { std::allocator<T>().deallocate(ptr, n); }
3738

3839
template <class U>
39-
friend bool operator==(const Allocator&, const Allocator<U>&) { return true; }
40+
friend bool operator==(const Allocator&, const Allocator<U>&) {
41+
return true;
42+
}
4043
};
4144

4245
struct ThrowingT {
@@ -138,7 +141,7 @@ int main(int, char**) {
138141
} catch (int) {
139142
}
140143
check_new_delete_called();
141-
#endif // TEST_STD_VER >= 14
144+
#endif // TEST_STD_VER >= 14
142145

143146
try { // Throw in vector(size_type, value_type, const allocator_type&) from the type
144147
int throw_after = 1;
@@ -217,11 +220,12 @@ int main(int, char**) {
217220
}
218221
check_new_delete_called();
219222

220-
try { // Throw in vector(vector&&, const allocator_type&) from type
221-
std::vector<ThrowingT, Allocator<ThrowingT> > vec(Allocator<ThrowingT>(false));
222-
int throw_after = 1;
223-
vec.emplace_back(throw_after);
224-
std::vector<ThrowingT, Allocator<ThrowingT> > vec2(std::move(vec), Allocator<ThrowingT>(false));
223+
try { // Throw in vector(vector&&, const allocator_type&) from type during element-wise move
224+
std::vector<ThrowingT, test_allocator<ThrowingT> > vec(test_allocator<ThrowingT>(1));
225+
int throw_after = 10;
226+
ThrowingT v(throw_after);
227+
vec.insert(vec.end(), 6, v);
228+
std::vector<ThrowingT, test_allocator<ThrowingT> > vec2(std::move(vec), test_allocator<ThrowingT>(2));
225229
} catch (int) {
226230
}
227231
check_new_delete_called();

0 commit comments

Comments
 (0)