-
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
noexceptions #88
Changes from 2 commits
d6b00ff
55e0e78
7cef9c6
43ed978
7810199
dd1f1ee
0b91e2d
25eb57b
4b951fc
d5041e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,17 @@ add_gtest(constructors) | |
| add_gtest(size_n_data) | ||
| add_gtest(erasure) | ||
|
|
||
| if( | ||
| CMAKE_CXX_COMPILER_ID STREQUAL "Clang" | ||
| OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" | ||
| ) | ||
| add_gtest(noexceptions) | ||
| target_compile_options( | ||
| beman.inplace_vector.tests.noexceptions | ||
| PRIVATE -fno-exceptions | ||
| ) | ||
|
Comment on lines
+55
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" |
||
| endif() | ||
|
|
||
| # constexpr test | ||
| add_executable(beman.inplace_vector.tests.constexpr constexpr.test.cpp) | ||
| target_link_libraries( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include <array> | ||
|
|
||
| bool abort_called = false; | ||
| #define BEMAN_IV_THROW(x) abort_called = true; | ||
20162026 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #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; | ||
| using T = TestFixture::T; | ||
|
|
||
| const auto reference = this->unique(); | ||
|
|
||
| IV device; | ||
| abort_called = false; | ||
|
|
||
| device.assign(reference.begin(), reference.end()); | ||
| EXPECT_EQ(device, reference); | ||
| device.clear(); | ||
|
|
||
| EXPECT_EQ(abort_called, false); | ||
| } | ||
|
|
||
| TYPED_TEST(NoExceptions, Throwing) { | ||
|
|
||
| using IV = TestFixture::IV; | ||
| using T = TestFixture::T; | ||
|
|
||
| const auto reference = this->unique(); | ||
| auto range = std::array<T, IV::capacity() + 1>{}; | ||
|
|
||
| IV device; | ||
| device.assign(reference.begin(), reference.end()); | ||
|
|
||
| abort_called = false; | ||
| device.emplace_back(T{}); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.resize(IV::capacity() + 1); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.resize(IV::capacity() + 1, T{}); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.reserve(IV::capacity() + 1); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.append_range(range); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.insert(device.end(), range.begin(), range.end()); | ||
| EXPECT_EQ(abort_called, true); | ||
|
|
||
| abort_called = false; | ||
| device.at(IV::capacity() + 1); | ||
| EXPECT_EQ(abort_called, true); | ||
| } | ||
| } // namespace | ||
Uh oh!
There was an error while loading. Please reload this page.