[PATCH 05/59] Support static_assert in pre-C23 C
Paul Eggert
eggert@cs.ucla.edu
Sun Jan 5 05:56:40 GMT 2025
* include/sys/cdefs.h (static_assert) [!C++ && __STDC_VERSION__ < 202311]:
New macro.
* timezone/private.h, timezone/version: Copy from tzcode git.
---
include/sys/cdefs.h | 8 ++++++++
timezone/private.h | 2 +-
timezone/version | 2 +-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h
index a676f75f62..cd3127aaca 100644
--- a/include/sys/cdefs.h
+++ b/include/sys/cdefs.h
@@ -7,6 +7,14 @@
# define _Static_assert(expr, diagnostic) _Static_assert (expr, diagnostic)
#endif
+/* Support single-arg static_assert in C code even on pre-C23 compilers,
+ for compatibility with Gnulib. */
+#if (!defined __cplusplus \
+ && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 202311) \
+ && !defined static_assert)
+# define static_assert(expr) _Static_assert (expr, #expr)
+#endif
+
#include <misc/sys/cdefs.h>
#ifndef _ISOMAC
diff --git a/timezone/private.h b/timezone/private.h
index c33041049f..3db0121135 100644
--- a/timezone/private.h
+++ b/timezone/private.h
@@ -50,7 +50,7 @@
# include <stdbool.h>
#endif
-#if __STDC_VERSION__ < 202311
+#if __STDC_VERSION__ < 202311 && !defined static_assert
# define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1]
#endif
diff --git a/timezone/version b/timezone/version
index 04fe674443..c6db4af447 100644
--- a/timezone/version
+++ b/timezone/version
@@ -1 +1 @@
-2024a
+2024b-11-gaf54a9e
--
2.45.2
More information about the Libc-alpha
mailing list