[libc] Make static_assert available even if NDEBUG is set (#99742)

This addresses an issue introduced in #98826 where static_assert was
made defined only when NDEBUG is not set which is different from all
other C libraries and breaks any code that uses static_assert and
doesn't guard it with NDEBUG.
This commit is contained in:
Petr Hosek 2024-07-20 00:56:52 -07:00 committed by GitHub
parent 867ff2d426
commit d386a5582b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,22 +12,19 @@
// This file may be usefully included multiple times to change assert()'s
// definition based on NDEBUG.
#undef assert
#ifdef NDEBUG
#define assert(e) (void)0
#else
#ifndef __cplusplus
#undef static_assert
#define static_assert _Static_assert
#endif
#undef assert
#ifdef NDEBUG
#define assert(e) (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__))
#endif