[libc-commits] [libc] 9124e96 - [libc] Update assert for C23 (#137402)
via libc-commits
libc-commits at lists.llvm.org
Mon Apr 28 12:06:56 PDT 2025
Author: Michael Jones
Date: 2025-04-28T15:06:52-04:00
New Revision: 9124e963a3bf73fd7430a17535d638601be5630f
URL: https://github.com/llvm/llvm-project/commit/9124e963a3bf73fd7430a17535d638601be5630f
DIFF: https://github.com/llvm/llvm-project/commit/9124e963a3bf73fd7430a17535d638601be5630f.diff
LOG: [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
Added:
Modified:
libc/include/assert.h.def
Removed:
################################################################################
diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index d5ae14a1cd810..2c27712251b17 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -19,14 +19,14 @@
#undef assert
#ifdef NDEBUG
-#define assert(e) (void)0
+#define assert(...) ((void)0)
#else
#ifdef __cplusplus
extern "C"
#endif
_Noreturn void __assert_fail(const char *, const char *, unsigned, const char *) __NOEXCEPT;
-#define assert(e) \
- ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__))
+#define assert(...) \
+ ((__VA_ARGS__) ? ((void)0) : __assert_fail(#__VA_ARGS__, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#endif
%%public_api()
More information about the libc-commits
mailing list