From 42f11222fd1e6dea59b56a5ae88802c03c7b937b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 11 Jan 2024 19:27:54 -0800 Subject: [PATCH] Simplify exception detection --- include/fmt/base.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index d3b5173261dd1..c67ce9f5871a0 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -54,6 +54,22 @@ # define FMT_LIBCPP_VERSION 0 #endif +// Check if exceptions are disabled. +#ifdef FMT_EXCEPTIONS +// Use the provided definition. +#elif FMT_GCC_VERSION && !defined(__EXCEPTIONS) +# define FMT_EXCEPTIONS 0 +#else +# define FMT_EXCEPTIONS (!FMT_MSC_VERSION && _HAS_EXCEPTIONS) +#endif +#if FMT_EXCEPTIONS +# define FMT_TRY try +# define FMT_CATCH(x) catch (x) +#else +# define FMT_TRY if (true) +# define FMT_CATCH(x) if (false) +#endif + #ifdef _MSVC_LANG # define FMT_CPLUSPLUS _MSVC_LANG #else @@ -119,23 +135,6 @@ # define FMT_CONSTEXPR20 #endif -// Check if exceptions are disabled. -#ifndef FMT_EXCEPTIONS -# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ - (FMT_MSC_VERSION && !_HAS_EXCEPTIONS) -# define FMT_EXCEPTIONS 0 -# else -# define FMT_EXCEPTIONS 1 -# endif -#endif -#if FMT_EXCEPTIONS -# define FMT_TRY try -# define FMT_CATCH(x) catch (x) -#else -# define FMT_TRY if (true) -# define FMT_CATCH(x) if (false) -#endif - // Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && \ !defined(__NVCC__)