Skip to content

Commit

Permalink
When using C++23, use [[assume]] attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed Jan 24, 2024
1 parent 8315924 commit 7d715d2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/deal.II/base/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,42 @@ namespace deal_II_exceptions
} /*namespace deal_II_exceptions*/


#ifdef DEAL_II_HAVE_CXX23
# define define DEAL_II_ASSUME(expr) [[assume(expr)]]
#else
# if defined(__clang__)
# define DEAL_II_ASSUME(expr) __builtin_assume(static_cast<bool>(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
#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,
Expand Down

0 comments on commit 7d715d2

Please sign in to comment.