[05/59] Support static_assert in pre-C23 C

Message ID 20250105055750.1668721-6-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:56 a.m. UTC
  * 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(-)
  

Patch

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