Skip to content

Commit 9124e96

Browse files
[libc] Update assert for C23 (#137402)
Previously the assert macro took one argument named "e", but this led to possible errors if the caller had commas in their input. C23 changed the definition of assert to use `__VA_ARGS__` to ensure comma cases are handled properly. This patch doesn't introduce the enforcement function mentioned in the standard update, though that may be done in a followup. Fixes #136184
1 parent abec9ff commit 9124e96

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/include/assert.h.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
#undef assert
2121
#ifdef NDEBUG
22-
#define assert(e) (void)0
22+
#define assert(...) ((void)0)
2323
#else
2424
#ifdef __cplusplus
2525
extern "C"
2626
#endif
2727
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
28-
#define assert(e) \
29-
((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
28+
#define assert(...) \
29+
((__VA_ARGS__) ? ((void)0) : __assert_fail(#__VA_ARGS__, __FILE__, __LINE__, __PRETTY_FUNCTION__))
3030
#endif
3131

3232
%%public_api()

0 commit comments

Comments
 (0)