From 9363f1243aa299e25908d761f45df3fbf122dfbf Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sun, 6 Oct 2024 11:09:42 +0000 Subject: [PATCH] include/ceph_assert: introduce consteval_assert `throw` in C++20's `consteval` function results in an ill-formed program. Useful as parameters of such functions aren't const- expressions, and thus are unsuitable for `static_assert`. Signed-off-by: Radoslaw Zarzynski --- src/include/ceph_assert.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/include/ceph_assert.h b/src/include/ceph_assert.h index 0627894ea6e..442e6bb6ac7 100644 --- a/src/include/ceph_assert.h +++ b/src/include/ceph_assert.h @@ -144,4 +144,10 @@ using namespace ceph; ? _CEPH_ASSERT_VOID_CAST (0) \ : ::ceph::__ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__)) +#define consteval_assert(expr, msg) \ + do { \ + if (!(expr)) { \ + throw (msg); \ + } \ + } while(false) #endif -- 2.47.3