Skip to content

Commit 9363f12

Browse files
committed
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 <[email protected]>
1 parent 4dd7f48 commit 9363f12

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/include/ceph_assert.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,10 @@ using namespace ceph;
144144
? _CEPH_ASSERT_VOID_CAST (0) \
145145
: ::ceph::__ceph_assertf_fail (__STRING(expr), __FILE__, __LINE__, __CEPH_ASSERT_FUNCTION, __VA_ARGS__))
146146

147+
#define consteval_assert(expr, msg) \
148+
do { \
149+
if (!(expr)) { \
150+
throw (msg); \
151+
} \
152+
} while(false)
147153
#endif

0 commit comments

Comments
 (0)