summaryrefslogtreecommitdiff
path: root/ucoo/common.hh
diff options
context:
space:
mode:
Diffstat (limited to 'ucoo/common.hh')
-rw-r--r--ucoo/common.hh15
1 files changed, 15 insertions, 0 deletions
diff --git a/ucoo/common.hh b/ucoo/common.hh
index 24ead61..708b9a1 100644
--- a/ucoo/common.hh
+++ b/ucoo/common.hh
@@ -52,6 +52,10 @@ access_once (T &x)
void
halt () __attribute__ ((noreturn));
+/// Stop, try to output error message.
+void
+halt (const char *msg) __attribute__ ((noreturn));
+
/// Stop, try to output error description corresponding to errno.
void
halt_perror () __attribute__ ((noreturn));
@@ -67,6 +71,17 @@ assert (bool condition)
halt ();
}
+void
+assert (bool condition, const char *msg) __attribute__ ((always_inline));
+extern inline void
+assert (bool condition, const char *msg)
+{
+ if (!__builtin_expect (condition, 1))
+ halt (msg);
+}
+
+#define assert(c) assert (c, #c)
+
/// To be used to swear that this code can never be reached.
void
assert_unreachable () __attribute__ ((noreturn));