Skip to content

Commit

Permalink
Hide std::exception_ptr and friends if exceptions disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthias Blankertz authored and horenmar committed Jun 12, 2020
1 parent 0f12995 commit 0614a4a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/internal/catch_registry_hub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/internal/catch_startup_exception_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,3 +25,4 @@ void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexce
}

} // end namespace Catch
#endif
2 changes: 2 additions & 0 deletions include/internal/catch_startup_exception_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/internal/catch_uncaught_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0614a4a

Please sign in to comment.