catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
WIP: More noexcept
- Commit
ace418200064a2467441f565f74ac41cf5884150- Author
- Martin Hořeňovský ·
- Parents
d59be347677f
Changes
src/catch2/internal/catch_assertion_handler.cpp | 4 ++-- src/catch2/internal/catch_assertion_handler.hpp | 24 +++++++++++++++------- .../matchers/internal/catch_matchers_impl.cpp | 2 +- .../matchers/internal/catch_matchers_impl.hpp | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/catch2/internal/catch_assertion_handler.cpp b/src/catch2/internal/catch_assertion_handler.cpp index e028c371..1bec6d3f 100644 --- a/src/catch2/internal/catch_assertion_handler.cpp +++ b/src/catch2/internal/catch_assertion_handler.cpp @@ -65,7 +65,7 @@ namespace Catch { m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); } - void AssertionHandler::handleExceptionThrownAsExpected() { + void AssertionHandler::handleExceptionThrownAsExpected() noexcept { m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); } void AssertionHandler::handleExceptionNotThrownAsExpected() { @@ -82,7 +82,7 @@ namespace Catch { // This is the overload that takes a string and infers the Equals matcher from it // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str ) { + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str ) noexcept { handleExceptionMatchExpr( handler, Matchers::Equals( str ) ); } diff --git a/src/catch2/internal/catch_assertion_handler.hpp b/src/catch2/internal/catch_assertion_handler.hpp index b92b80eb..d7d3719e 100644 --- a/src/catch2/internal/catch_assertion_handler.hpp +++ b/src/catch2/internal/catch_assertion_handler.hpp @@ -55,17 +55,22 @@ namespace Catch { void handleMessage(ResultWas::OfType resultType, std::string&& message); - void handleExceptionThrownAsExpected(); - void handleUnexpectedExceptionNotThrown(); - void handleExceptionNotThrownAsExpected(); - void handleThrowingCallSkipped(); // TODO: // * called from catch (...) blocks in assertions // * doesn't propagate exception - // * Allows the compiler to skip adding more exception edges in catch (...) when it cannot throw + // * Allows the compiler to skip adding more exception edges in catch + // (...) when it cannot throw // * compilation is faster - // * abort on throw inside is fine -> this is called when another exception is called, so it would abort anyway + // * abort on throw inside is fine -> this is called when another + // exception is called, so it would abort anyway void handleUnexpectedInflightException() noexcept; + // TODO: + // * similar reasoning as above, unified comment for both + void handleExceptionThrownAsExpected() noexcept; + + void handleUnexpectedExceptionNotThrown(); + void handleExceptionNotThrownAsExpected(); + void handleThrowingCallSkipped(); void complete(); @@ -73,7 +78,12 @@ namespace Catch { auto allowThrows() const -> bool; }; - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str ); + // Like the two handlers above, this is only ever called from inside the + // `catch` block of an assertion macro, so an exception escaping it would + // already terminate. Saying so explicitly keeps the compiler from emitting + // a nested exception edge at every expansion of `REQUIRE_THROWS_WITH` and + // friends. + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str ) noexcept; } // namespace Catch diff --git a/src/catch2/matchers/internal/catch_matchers_impl.cpp b/src/catch2/matchers/internal/catch_matchers_impl.cpp index 41b462e5..6a524ff6 100644 --- a/src/catch2/matchers/internal/catch_matchers_impl.cpp +++ b/src/catch2/matchers/internal/catch_matchers_impl.cpp @@ -16,7 +16,7 @@ namespace Catch { // This is the general overload that takes a any string matcher // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers // the Equals matcher (so the header does not mention matchers) - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ) { + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ) noexcept { std::string exceptionMessage = Catch::translateActiveException(); MatchExpr<std::string, StringMatcher const&> expr( CATCH_MOVE(exceptionMessage), matcher ); handler.handleExpr( expr ); diff --git a/src/catch2/matchers/internal/catch_matchers_impl.hpp b/src/catch2/matchers/internal/catch_matchers_impl.hpp index 1aa50385..87667b46 100644 --- a/src/catch2/matchers/internal/catch_matchers_impl.hpp +++ b/src/catch2/matchers/internal/catch_matchers_impl.hpp @@ -60,7 +60,7 @@ namespace Catch { using StringMatcher = Matchers::MatcherBase<std::string>; - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ); + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ) noexcept; template<typename ArgT, typename MatcherT> constexpr MatchExpr<ArgT, MatcherT>