diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e4eab51..2c6aaba3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_common.hpp ${SOURCES_DIR}/internal/catch_compiler_capabilities.hpp ${SOURCES_DIR}/catch_config.hpp + ${SOURCES_DIR}/internal/catch_config_uncaught_exceptions.hpp ${SOURCES_DIR}/internal/catch_console_colour.hpp ${SOURCES_DIR}/internal/catch_context.hpp ${SOURCES_DIR}/internal/catch_debug_console.hpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 00eca956..6e93d54c 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include diff --git a/src/catch2/internal/catch_combined_tu.cpp b/src/catch2/internal/catch_combined_tu.cpp index 021368b3..c3ed9e2b 100644 --- a/src/catch2/internal/catch_combined_tu.cpp +++ b/src/catch2/internal/catch_combined_tu.cpp @@ -76,13 +76,15 @@ namespace Catch { #include #include +#include + #include namespace Catch { bool 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)) +#elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) return std::uncaught_exceptions() > 0; #else return std::uncaught_exception(); diff --git a/src/catch2/internal/catch_config_uncaught_exceptions.hpp b/src/catch2/internal/catch_config_uncaught_exceptions.hpp new file mode 100644 index 00000000..eac9078e --- /dev/null +++ b/src/catch2/internal/catch_config_uncaught_exceptions.hpp @@ -0,0 +1,44 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/** \file + * Wrapper for UNCAUGHT_EXCEPTIONS configuration option + * + * For some functionality, Catch2 requires to know whether there is + * an active exception. Because `std::uncaught_exception` is deprecated + * in C++17, we want to use `std::uncaught_exceptions` if possible. + */ + +#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP +#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP + +#if defined(_MSC_VER) +# if _MSC_VER >= 1900 // Visual Studio 2015 or newer +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +# endif +#endif + + +#include + +#if defined(__cpp_lib_uncaught_exceptions) \ + && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif // __cpp_lib_uncaught_exceptions + + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \ + && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \ + && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) + +# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + + +#endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP