From: Matthias Maier Date: Fri, 19 Jan 2024 17:15:04 +0000 (-0600) Subject: config.h: for consistency move DEAL_II_ASSUME macro to config.h.in X-Git-Tag: relicensing~132^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31c9a779b538e4ad86f0f1ae5045d49ceccfbc7b;p=dealii.git config.h: for consistency move DEAL_II_ASSUME macro to config.h.in --- diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 9ca48428da..8dbd40e313 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -155,6 +155,17 @@ #cmakedefine DEAL_II_HAVE_CXX20 #cmakedefine DEAL_II_HAVE_CXX23 +#cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS +#cmakedefine DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS +#cmakedefine DEAL_II_HAVE_CXX17_BESSEL_FUNCTIONS +#cmakedefine DEAL_II_CXX14_CONSTEXPR_BUG + +// The following three are defined for backwards compatibility with older +// deal.II versions: +#define DEAL_II_WITH_CXX11 +#define DEAL_II_WITH_CXX14 +#define DEAL_II_WITH_CXX17 + /** * If we have C++20 available, we can have concepts and requires * clauses. We want to avoid using too many `#ifdef` statements, so @@ -167,10 +178,33 @@ # define DEAL_II_CXX20_REQUIRES(condition) #endif -#cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS -#cmakedefine DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS -#cmakedefine DEAL_II_HAVE_CXX17_BESSEL_FUNCTIONS -#cmakedefine DEAL_II_CXX14_CONSTEXPR_BUG +/** + * Provide support for the C++23 [[assume]] attribute. To mimic the + * attribute for older standards we rely on compiler intrinsics when + * available. + */ +#if defined(__clang__) +# define DEAL_II_ASSUME(expr) __builtin_assume(static_cast(expr)) +#elif defined(__GNUC__) && !defined(__ICC) && __GNUC__ >= 13 +# define DEAL_II_ASSUME(expr) \ + do \ + { \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \ + [[assume(expr)]]; \ + _Pragma("GCC diagnostic pop") \ + } \ + while (false) +#elif defined(_MSC_VER) || defined(__ICC) +# define DEAL_II_ASSUME(expr) __assume(expr); +#else +/* no way with GCC to express this without evaluating 'expr' */ +# define DEAL_II_ASSUME(expr) \ + do \ + { \ + } \ + while (false) +#endif /** * Macro indicating that the current feature will be removed in a future @@ -207,11 +241,6 @@ #cmakedefine DEAL_II_FALLTHROUGH @DEAL_II_FALLTHROUGH@ #cmakedefine DEAL_II_CONSTEXPR @DEAL_II_CONSTEXPR@ -// The following three are defined for backwards compatibility with older deal.II versions: -#define DEAL_II_WITH_CXX11 -#define DEAL_II_WITH_CXX14 -#define DEAL_II_WITH_CXX17 - /*********************************************************************** * System features: diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 2453809e53..a82b4eeacd 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -1519,38 +1519,6 @@ namespace deal_II_exceptions } /*namespace deal_II_exceptions*/ -#if defined(__clang__) -# define DEAL_II_ASSUME(expr) __builtin_assume(static_cast(expr)) -#elif defined(__GNUC__) && !defined(__ICC) -# if __GNUC__ >= 13 -# define DEAL_II_ASSUME(expr) \ - do \ - { \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \ - [[assume(expr)]]; \ - _Pragma("GCC diagnostic pop") \ - } \ - while (false) -# else -/* no way with GCC to express this without evaluating 'expr' */ -# define DEAL_II_ASSUME(expr) \ - do \ - { \ - } \ - while (false) -# endif -#elif defined(_MSC_VER) || defined(__ICC) -# define DEAL_II_ASSUME(expr) __assume(expr); -#else -# define DEAL_II_ASSUME(expr) \ - do \ - { \ - } \ - while (false) -#endif - - /** * A macro that serves as the main routine in the exception mechanism for debug * mode error checking. It asserts that a certain condition is fulfilled,