-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++][test] Fix and refactor exception tests for std::vector #117641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| try { // Throw in vector(size_type, const allocator_type&) from allocator | ||
| throwing_allocator<int> alloc(false, true); // throw on copy only | ||
| AllocVec get_alloc(0, alloc); | ||
| } catch (int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test did not throw.
| int a[] = {1, 2}; | ||
| Allocator<int> alloc(false); | ||
| throwing_allocator<int> alloc(false, true); // throw on copy only | ||
| AllocVec vec(cpp17_input_iterator<int*>(a), cpp17_input_iterator<int*>(a + 2), alloc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test did not throw.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test did not throw.
| int throw_after = 1; | ||
| vec.emplace_back(throw_after); | ||
| auto vec2 = vec; | ||
| } catch (int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test threw in the emplace_back call, not in vector(const vector&).
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test did not throw.
977dd93 to
d8ea0f9
Compare
d8ea0f9 to
bf2a0b1
Compare
The existing exceptions tests for
vector<T>have several issues: some tests did not throw exceptions at all, making them not useless for exception-safety testing, and some tests did not throw exceptions at the intended points, failing to serve their expected purpose. This PR fixes all those tests. Morever, this PR extracted common classes and utilities into a separate header file, and renamed those classes using more descriptive names.For your convenience, I have added comments on the problematic tests.