[libcxx-commits] [libcxx] [libc++][test] Fix and refactor exception tests for std::vector (PR #117641)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 25 15:41:58 PST 2024
================
@@ -192,51 +115,52 @@ int main(int, char**) {
try { // Throw in vector(InputIterator, InputIterator, const allocator_type&) from allocator
int a[] = {1, 2};
- Allocator<int> alloc(false);
+ throwing_allocator<int> alloc(false, true); // throw on copy only
AllocVec vec(forward_iterator<int*>(a), forward_iterator<int*>(a + 2), alloc);
} catch (int) {
// FIXME: never called.
}
check_new_delete_called();
try { // Throw in vector(const vector&) from type
- std::vector<ThrowingT> vec;
- int throw_after = 0;
+ std::vector<throwing_t> vec;
+ int throw_after = 1;
vec.emplace_back(throw_after);
auto vec2 = vec;
} catch (int) {
}
check_new_delete_called();
try { // Throw in vector(const vector&, const allocator_type&) from type
- std::vector<ThrowingT> vec;
+ std::vector<throwing_t> vec;
int throw_after = 1;
vec.emplace_back(throw_after);
- std::vector<ThrowingT> vec2(vec, std::allocator<int>());
+ std::vector<throwing_t> vec2(vec, std::allocator<int>());
} catch (int) {
}
check_new_delete_called();
- try { // Throw in vector(vector&&, const allocator_type&) from type
- std::vector<ThrowingT, Allocator<ThrowingT> > vec(Allocator<ThrowingT>(false));
- int throw_after = 1;
- vec.emplace_back(throw_after);
- std::vector<ThrowingT, Allocator<ThrowingT> > vec2(std::move(vec), Allocator<ThrowingT>(false));
+ try { // Throw in vector(vector&&, const allocator_type&) from type during element-wise move
+ std::vector<throwing_t, test_allocator<throwing_t> > vec(test_allocator<throwing_t>(1));
+ int throw_after = 10;
+ throwing_t v(throw_after);
+ vec.insert(vec.end(), 6, v);
+ std::vector<throwing_t, test_allocator<throwing_t> > vec2(std::move(vec), test_allocator<throwing_t>(2));
} catch (int) {
----------------
winner245 wrote:
This test did not throw.
https://github.com/llvm/llvm-project/pull/117641
More information about the libcxx-commits
mailing list