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
Hide std::exception_ptr and friends if exceptions disabled
- Commit
9221a6ff653a4f4c6f981675122064da7d7b356d- Author
- Matthias Blankertz ·
- Committer
- Martin Hořeňovský
- Parents
657ebf5db2b4
Changes
src/catch2/catch_registry_hub.cpp | 5 +++++ src/catch2/internal/catch_combined_tu.cpp | 8 ++++++-- src/catch2/internal/catch_startup_exception_registry.hpp | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp index ed2d068a..a8860e3a 100644 --- a/src/catch2/catch_registry_hub.cpp +++ b/src/catch2/catch_registry_hub.cpp @@ -9,6 +9,7 @@ #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> #include <catch2/internal/catch_context.hpp> +#include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_test_case_registry_impl.hpp> #include <catch2/internal/catch_reporter_registry.hpp> #include <catch2/internal/catch_exception_translator_registry.hpp> @@ -59,7 +60,11 @@ namespace Catch { m_tagAliasRegistry.add( alias, tag, lineInfo ); } void registerStartupException() noexcept override { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) m_exceptionRegistry.add(std::current_exception()); +#else + CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); +#endif } IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override { return m_enumValuesRegistry; diff --git a/src/catch2/internal/catch_combined_tu.cpp b/src/catch2/internal/catch_combined_tu.cpp index fcb05093..c18d4cc7 100644 --- a/src/catch2/internal/catch_combined_tu.cpp +++ b/src/catch2/internal/catch_combined_tu.cpp @@ -73,7 +73,9 @@ namespace Catch { namespace Catch { bool uncaught_exceptions() { -#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) || (defined(__cpp_lib_uncaught_exceptions) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS)) +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + return false; +#elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) || (defined(__cpp_lib_uncaught_exceptions) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS)) return std::uncaught_exceptions() > 0; #else return std::uncaught_exception(); @@ -122,7 +124,8 @@ namespace Catch { #include <catch2/internal/catch_compiler_capabilities.hpp> namespace Catch { -void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) + void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { CATCH_TRY { m_exceptions.push_back(exception); } CATCH_CATCH_ALL { @@ -134,6 +137,7 @@ void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexce std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept { return m_exceptions; } +#endif } // end namespace Catch diff --git a/src/catch2/internal/catch_startup_exception_registry.hpp b/src/catch2/internal/catch_startup_exception_registry.hpp index feb56601..366312ad 100644 --- a/src/catch2/internal/catch_startup_exception_registry.hpp +++ b/src/catch2/internal/catch_startup_exception_registry.hpp @@ -15,11 +15,13 @@ namespace Catch { class StartupExceptionRegistry { +#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) public: void add(std::exception_ptr const& exception) noexcept; std::vector<std::exception_ptr> const& getExceptions() const noexcept; private: std::vector<std::exception_ptr> m_exceptions; +#endif }; } // end namespace Catch