]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
include/ceph_assert: introduce consteval_assert
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Sun, 6 Oct 2024 11:09:42 +0000 (11:09 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 18 Mar 2025 11:25:09 +0000 (11:25 +0000)
`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 <rzarzyns@redhat.com>
src/include/ceph_assert.h

index 0627894ea6e07d5d4451d3be29f9ab09b75cc6d7..442e6bb6ac740e33aaba9583900ab35ff93d8ef5 100644 (file)
@@ -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