From 0badb9398ae81fb083e8c86fb137b31159d7bae9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 11 Jan 2024 14:31:14 -0700 Subject: [PATCH] When using C++23, use [[assume]] attribute. --- include/deal.II/base/config.h.in | 21 +++++++++++++-------- include/deal.II/base/exceptions.h | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index c9943b3efe..5e468bc133 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -183,10 +183,13 @@ * attribute for older standards we rely on compiler intrinsics when * available. */ -#if defined(__clang__) -# define DEAL_II_CXX23_ASSUME(expr) __builtin_assume(static_cast(expr)) -#elif defined(__GNUC__) && !defined(__ICC) && __GNUC__ >= 13 -# define DEAL_II_CXX23_ASSUME(expr) \ +#ifdef DEAL_II_HAVE_CXX23 +# define define DEAL_II_ASSUME(expr) [[assume(expr)]] +#else +# if defined(__clang__) +# define DEAL_II_CXX23_ASSUME(expr) __builtin_assume(static_cast(expr)) +# elif defined(__GNUC__) && !defined(__ICC) && __GNUC__ >= 13 +# define DEAL_II_CXX23_ASSUME(expr) \ do \ { \ _Pragma("GCC diagnostic push") \ @@ -195,17 +198,19 @@ _Pragma("GCC diagnostic pop") \ } \ while (false) -#elif defined(_MSC_VER) || defined(__ICC) -# define DEAL_II_CXX23_ASSUME(expr) __assume(expr); -#else +# elif defined(_MSC_VER) || defined(__ICC) +# define DEAL_II_CXX23_ASSUME(expr) __assume(expr); +# else /* no way with GCC to express this without evaluating 'expr' */ -# define DEAL_II_CXX23_ASSUME(expr) \ +# define DEAL_II_CXX23_ASSUME(expr) \ do \ { \ } \ while (false) +# endif #endif + /** * Macro indicating that the current feature will be removed in a future * release. diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 99dceb5450..4adb7483ba 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -1519,6 +1519,7 @@ namespace deal_II_exceptions } /*namespace deal_II_exceptions*/ + /** * 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, -- 2.39.5