From 27e7fd18f1c337c409f2a567697b27bcd0c09f8b Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Wed, 7 Jul 2021 17:12:12 -0400 Subject: Support manually disabling exceptions Rename EIGEN_EXCEPTIONS to EIGEN_USE_EXCEPTIONS, and allow disabling exceptions with -DEIGEN_USE_EXCEPTIONS=0. --- test/ctorleak.cpp | 13 +++++-------- test/main.h | 18 +++++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/ctorleak.cpp b/test/ctorleak.cpp index 73904176b..e76a4a7ba 100644 --- a/test/ctorleak.cpp +++ b/test/ctorleak.cpp @@ -10,7 +10,7 @@ struct Foo Foo() : dummy(0) { -#ifdef EIGEN_EXCEPTIONS +#if EIGEN_USE_EXCEPTIONS // TODO: Is this the correct way to handle this? if (Foo::object_count > Foo::object_limit) { std::cout << "\nThrow!\n"; throw Foo::Fail(); } #endif @@ -46,10 +46,7 @@ EIGEN_DECLARE_TEST(ctorleak) MatrixX r(rows, cols); Foo::object_limit = r.size()+internal::random(0, rows*cols - 2); std::cout << "object_limit =" << Foo::object_limit << std::endl; -#ifdef EIGEN_EXCEPTIONS - try - { -#endif + EIGEN_TRY { if(internal::random()) { std::cout << "\nMatrixX m(" << rows << ", " << cols << ");\n"; MatrixX m(rows, cols); @@ -58,11 +55,11 @@ EIGEN_DECLARE_TEST(ctorleak) std::cout << "\nMatrixX m(r);\n"; MatrixX m(r); } -#ifdef EIGEN_EXCEPTIONS +#if EIGEN_USE_EXCEPTIONS VERIFY(false); // not reached if exceptions are enabled - } - catch (const Foo::Fail&) { /* ignore */ } #endif + } + EIGEN_CATCH(const Foo::Fail&) { /* ignore */ } } VERIFY_IS_EQUAL(Index(0), Foo::object_count); diff --git a/test/main.h b/test/main.h index 786673dea..77943040b 100644 --- a/test/main.h +++ b/test/main.h @@ -209,8 +209,12 @@ namespace Eigen #define EIGEN_DEFAULT_IO_FORMAT IOFormat(4, 0, " ", "\n", "", "", "", "") -#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) && !defined(__HIP_DEVICE_COMPILE__) && !defined(__SYCL_DEVICE_ONLY__) - #define EIGEN_EXCEPTIONS +#ifndef EIGEN_USE_EXCEPTIONS + #if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) && !defined(__HIP_DEVICE_COMPILE__) && !defined(__SYCL_DEVICE_ONLY__) + #define EIGEN_USE_EXCEPTIONS 1 + #else + #define EIGEN_USE_EXCEPTIONS 0 + #endif #endif #ifndef EIGEN_NO_ASSERTION_CHECKING @@ -267,7 +271,7 @@ namespace Eigen eigen_assert_list.push_back(std::string(EIGEN_MAKESTRING(__FILE__) " (" EIGEN_MAKESTRING(__LINE__) ") : " #a) ); \ } - #ifdef EIGEN_EXCEPTIONS + #if EIGEN_USE_EXCEPTIONS #define VERIFY_RAISES_ASSERT(a) \ { \ Eigen::no_more_assert = false; \ @@ -286,7 +290,7 @@ namespace Eigen Eigen::report_on_cerr_on_assert_failure = true; \ Eigen::internal::push_assert = false; \ } - #endif //EIGEN_EXCEPTIONS + #endif //EIGEN_USE_EXCEPTIONS #elif !defined(__CUDACC__) && !defined(__HIPCC__) && !defined(SYCL_DEVICE_ONLY) // EIGEN_DEBUG_ASSERTS // see bug 89. The copy_bool here is working around a bug in gcc <= 4.3 @@ -300,7 +304,7 @@ namespace Eigen EIGEN_THROW_X(Eigen::eigen_assert_exception()); \ } - #ifdef EIGEN_EXCEPTIONS + #if EIGEN_USE_EXCEPTIONS #define VERIFY_RAISES_ASSERT(a) { \ Eigen::no_more_assert = false; \ Eigen::report_on_cerr_on_assert_failure = false; \ @@ -311,10 +315,10 @@ namespace Eigen catch (Eigen::eigen_assert_exception&) { VERIFY(true); } \ Eigen::report_on_cerr_on_assert_failure = true; \ } - #endif // EIGEN_EXCEPTIONS + #endif // EIGEN_USE_EXCEPTIONS #endif // EIGEN_DEBUG_ASSERTS - #if defined(TEST_CHECK_STATIC_ASSERTIONS) && defined(EIGEN_EXCEPTIONS) + #if defined(TEST_CHECK_STATIC_ASSERTIONS) && EIGEN_USE_EXCEPTIONS #define EIGEN_STATIC_ASSERT(a,MSG) \ if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) )\ { \ -- cgit v1.2.3