Skip to content

Commit 98422a1

Browse files
committed
libc: Add variadic assert in accordance with C23
Signed-off-by: Faraz Vahedi <kfv@kfv.io>
1 parent 56cb499 commit 98422a1

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

include/assert.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include <sys/cdefs.h>
3838

39+
#include <stdbool.h>
40+
3941
/*
4042
* Unlike other ANSI header files, <assert.h> may usefully be included
4143
* multiple times, with and without NDEBUG defined.
@@ -46,16 +48,17 @@
4648
#undef __assert_unreachable
4749

4850
#ifdef NDEBUG
49-
#define assert(e) ((void)0)
50-
#define _assert(e) ((void)0)
51+
#define assert(...) ((void)0)
52+
#define _assert(...) ((void)0)
5153
#if __BSD_VISIBLE
5254
#define __assert_unreachable() __unreachable()
5355
#endif /* __BSD_VISIBLE */
5456
#else
55-
#define _assert(e) assert(e)
56-
57-
#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \
58-
__LINE__, #e))
57+
#define assert(...) ((void)sizeof(((bool(*)(bool))0)(__VA_ARGS__)), \
58+
(__VA_ARGS__) ? (void)0 : \
59+
__assert(__func__, __FILE__, \
60+
__LINE__, #__VA_ARGS__))
61+
#define _assert(...) assert(__VA_ARGS__)
5962
#if __BSD_VISIBLE
6063
#define __assert_unreachable() assert(0 && "unreachable segment reached")
6164
#endif /* __BSD_VISIBLE */

0 commit comments

Comments
 (0)