Rename static_assert to avoid conflicting with C++'11 (and later) (XCC)
[akaros.git] / user / parlib / include / assert.h
1 /* See COPYRIGHT for copyright information. */
2
3 #ifndef PARLIB_ASSERT_H
4 #define PARLIB_ASSERT_H
5
6 #ifdef BUILDING_PARLIB
7 # include_next "assert.h"
8 #else
9 # include <assert.h>
10 #endif
11 /* For __BEGIN_DECLS.  Most every header gets it already from features.h. */
12 #include <sys/cdefs.h>
13 /* So we can undefine warn */
14 #include <err.h>
15
16 __BEGIN_DECLS
17
18 #undef assert
19 #undef warn
20
21 void _warn(const char*, int, const char*, ...);
22 void _panic(const char*, int, const char*, ...) __attribute__((noreturn));
23 void _assert_failed(const char *file, int line, const char *msg)
24      __attribute__((noreturn));
25
26 #define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__)
27 #define panic(...) _panic(__FILE__, __LINE__, __VA_ARGS__)
28
29 #define assert(x)                                                                  \
30         do {                                                                       \
31                 if (!(x))                                                              \
32                         _assert_failed(__FILE__, __LINE__, #x);                            \
33         } while (0)
34
35 // parlib_static_assert(x) will generate a compile-time error if 'x' is false.
36 #define parlib_static_assert(x) switch (x) case 0: case (x):
37
38 __END_DECLS
39
40 #endif /* PARLIB_ASSERT_H */