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

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Fri Jul 19 22:57:56 PDT 2024


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/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.

>From 0e1bc23beecd82142e7632d3e8817d875950f5c6 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Fri, 19 Jul 2024 22:53:42 -0700
Subject: [PATCH] [libc] Make static_assert available even if NDEBUG is set

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.
---
 libc/include/assert.h.def | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/libc/include/assert.h.def b/libc/include/assert.h.def
index 9c924c7f58545..d5ae14a1cd810 100644
--- a/libc/include/assert.h.def
+++ b/libc/include/assert.h.def
@@ -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



More information about the libc-commits mailing list