Progmasoft Git

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

Some compilers, e.g. the Green Hills C++ compiler, react badly to the
appearance of std::exception_ptr, std::current_exception,
std::rethrow_exception and std::uncaught_exception(s). To allow usage of
Catch2 with these compilers when exceptions are disabled, hide the usage
of std::exception_ptr etc. when compiling with
CATCH_CONFIG_DISABLE_EXCEPTIONS.
Commit
0614a4acb36ef19d70a451b92a038e7d1e93941d
Author
Matthias Blankertz ·
Committer
Martin Hořeňovský
Parents
0f12995501ee

Files · Download .tar.gz

Changes

 include/internal/catch_registry_hub.cpp               | 4 ++++
 include/internal/catch_startup_exception_registry.cpp | 2 ++
 include/internal/catch_startup_exception_registry.h   | 2 ++
 include/internal/catch_uncaught_exceptions.cpp        | 4 +++-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/internal/catch_registry_hub.cpp b/include/internal/catch_registry_hub.cpp
index 8a3c7a97..852b34e0 100644
--- a/include/internal/catch_registry_hub.cpp
+++ b/include/internal/catch_registry_hub.cpp
@@ -59,7 +59,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/include/internal/catch_startup_exception_registry.cpp b/include/internal/catch_startup_exception_registry.cpp
index 3c5bd22f..04e46170 100644
--- a/include/internal/catch_startup_exception_registry.cpp
+++ b/include/internal/catch_startup_exception_registry.cpp
@@ -9,6 +9,7 @@
 #include "catch_startup_exception_registry.h"
 #include "catch_compiler_capabilities.h"
 
+#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
 namespace Catch {
 void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept {
         CATCH_TRY {
@@ -24,3 +25,4 @@ void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexce
     }
 
 } // end namespace Catch
+#endif
diff --git a/include/internal/catch_startup_exception_registry.h b/include/internal/catch_startup_exception_registry.h
index feb56601..366312ad 100644
--- a/include/internal/catch_startup_exception_registry.h
+++ b/include/internal/catch_startup_exception_registry.h
@@ -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
diff --git a/include/internal/catch_uncaught_exceptions.cpp b/include/internal/catch_uncaught_exceptions.cpp
index b990ccd8..22b1ed43 100644
--- a/include/internal/catch_uncaught_exceptions.cpp
+++ b/include/internal/catch_uncaught_exceptions.cpp
@@ -12,7 +12,9 @@
 
 namespace Catch {
     bool uncaught_exceptions() {
-#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
+#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
+        return false;
+#elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
         return std::uncaught_exceptions() > 0;
 #else
         return std::uncaught_exception();