From ae553056d65a765f1af690f1c8ef5a12628399f7 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 15 Jun 2024 19:04:55 +0300
Subject: [PATCH 28/28] Meson: Add C23 static_assert() support

See RM #692

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 gen_headers/meson_freeciv_config.h.in | 3 +++
 meson.build                           | 7 +++++++
 utility/log.h                         | 5 ++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gen_headers/meson_freeciv_config.h.in b/gen_headers/meson_freeciv_config.h.in
index cebda268fb..7ead843ff8 100644
--- a/gen_headers/meson_freeciv_config.h.in
+++ b/gen_headers/meson_freeciv_config.h.in
@@ -173,6 +173,9 @@
 /* Delta protocol enabled */
 #mesondefine FREECIV_DELTA_PROTOCOL
 
+/* C23 static assert supported */
+#mesondefine FREECIV_C23_STATIC_ASSERT
+
 /* C11 static assert supported */
 #mesondefine FREECIV_C11_STATIC_ASSERT
 
diff --git a/meson.build b/meson.build
index 386251d4e0..c5dd8bdce9 100644
--- a/meson.build
+++ b/meson.build
@@ -585,6 +585,13 @@ if zstd_dep.found()
   pub_conf_data.set('FREECIV_HAVE_LIBZSTD', 1)
 endif
 
+if c_compiler.compiles('''
+#include <assert.h>
+int main(void) { static_assert(1, "1 is not true"); }''',
+  name: 'c23 Static Assert')
+  pub_conf_data.set('FREECIV_C23_STATIC_ASSERT', 1)
+endif
+
 if c_compiler.compiles('''
 #include <assert.h>
 int main(void) { _Static_assert(1, "1 is not true"); }''',
diff --git a/utility/log.h b/utility/log.h
index 2dd7313245..ede45b09ad 100644
--- a/utility/log.h
+++ b/utility/log.h
@@ -17,6 +17,7 @@
 extern "C" {
 #endif /* __cplusplus */
 
+#include <assert.h>
 #include <stdarg.h>
 #include <stdlib.h>
 
@@ -218,7 +219,9 @@ void fc_assert_fail(const char *file, const char *function, int line,
 #define FC_STATIC_ASSERT(cond, tag) static_assert(cond, #tag)
 #endif /* FREECIV_CXX11_STATIC_ASSERT */
 #else  /* __cplusplus */
-#ifdef FREECIV_C11_STATIC_ASSERT
+#ifdef FREECIV_C23_STATIC_ASSERT
+#define FC_STATIC_ASSERT(cond, tag) static_assert(cond, #tag)
+#elif defined(FREECIV_C11_STATIC_ASSERT)
 #define FC_STATIC_ASSERT(cond, tag) _Static_assert(cond, #tag)
 #endif /* FREECIV_C11_STATIC_ASSERT */
 #ifdef FREECIV_STATIC_STRLEN
-- 
2.43.0

