-
Notifications
You must be signed in to change notification settings - Fork 11
noexceptions #88
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
Merged
Merged
noexceptions #88
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6b00ff
Add noexceptions support
20162026 55e0e78
Update fixed size assignment op and constructors
20162026 7cef9c6
Merge remote-tracking branch 'origin/main' into feature/noexceptions
20162026 43ed978
Update throw macro
20162026 7810199
Update noexceptions.test.cpp
20162026 dd1f1ee
Update noexceptions.test.cpp
20162026 0b91e2d
Add BEMAN_INPLACE_VECTOR_NO_EXCEPTIONS cmake option
20162026 25eb57b
Update noexceptions macro
20162026 4b951fc
Add no exceptions support for tests
20162026 d5041e4
Optimize noexception testing
20162026 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #include <array> | ||
|
|
||
| #include "gtest_setup.hpp" | ||
|
|
||
| namespace { | ||
|
|
||
| template <typename Param> class NoExceptions : public IVBasicTest<Param> {}; | ||
| TYPED_TEST_SUITE(NoExceptions, IVAllTypes); | ||
20162026 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| TYPED_TEST(NoExceptions, NonThrowing) { | ||
|
|
||
| using IV = TestFixture::IV; | ||
|
|
||
| const auto reference = this->unique(); | ||
|
|
||
| IV device; | ||
|
|
||
| device.assign(reference.begin(), reference.end()); | ||
| EXPECT_EQ(device, reference); | ||
| device.clear(); | ||
| } | ||
|
|
||
| TYPED_TEST(NoExceptions, IVAllTypes) { | ||
|
|
||
| using IV = TestFixture::IV; | ||
| using T = TestFixture::T; | ||
|
|
||
| IV sanitycheck = this->unique(); | ||
| EXPECT_EQ(sanitycheck.size(), IV::capacity()); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| device.emplace_back(T{}); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| device.resize(IV::capacity() + 1); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| device.resize(IV::capacity() + 1, T{}); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| device.reserve(IV::capacity() + 1); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device{}; | ||
| device.append_range(std::array<T, IV::capacity() + 2>{}); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| device.append_range(std::array<T, 2>{}); | ||
| }, | ||
| ".*"); | ||
|
|
||
| // TODO consider adding test for append_range of unsized range | ||
|
|
||
| if constexpr (IV::capacity() > 0) { | ||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| // test macro fails to compile if we use std::array<T, N> without | ||
| // parenthesis () | ||
| auto range = (std::array<T, IV::capacity()>{}); | ||
| device.insert(device.end(), range.begin(), range.end()); | ||
| }, | ||
| ".*"); | ||
| } | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device{}; | ||
| // test macro fails to compile if we use std::array<T, N> without | ||
| // parenthesis () | ||
| auto range = (std::array<T, IV::capacity() + 1>{}); | ||
| device.insert(device.end(), range.begin(), range.end()); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device = this->unique(); | ||
| auto e = device.at(IV::capacity() + 1); | ||
| }, | ||
| ".*"); | ||
|
|
||
| EXPECT_DEATH( | ||
| { | ||
| IV device; | ||
| const auto e = device.at(IV::capacity() + 1); | ||
| }, | ||
| ".*"); | ||
| } | ||
| } // namespace | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this still needed?
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.
Yes, it ensures that there are no throws in the compiled code. Without it, EXPECT_DEATH could still pass if an unhandled exception was thrown.
Although, I'm now not sure if we need the compiler check. It allows running the tests on compilers that don't support or have a different syntax for disabling exceptions (e.g. MSVC). But right now, CI only includes Clang and GCC, and maybe it would be better to error out instead of silently skipping tests on other compilers. On the other hand, it doesn't matter much, as the implementation should be compiler agnostic as long as there is abort()