[php-src] master: tree-wide: Replace `ZEND_STATIC_ASSERT()` by `static_assert()` (#21228)
| From: | Tim Düsterhus via GitHub | Date: | Fri, 25 Sep 2026 10:21:04 +0000 |
| Subject: | [php-src] master: tree-wide: Replace `ZEND_STATIC_ASSERT()` by `static_assert()` (#21228) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141532@lists.php.net to get a copy of this message | ||
Author: Tim Düsterhus (TimWolla)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2026-09-25T12:21:01+02:00
Commit: https://github.com/php/php-src/commit/c5e45a17674bb2b34e308a2ecfff6e8462a601c7
Raw diff: https://github.com/php/php-src/commit/c5e45a17674bb2b34e308a2ecfff6e8462a601c7.diff
tree-wide: Replace
ZEND_STATIC_ASSERT() by static_assert() (#21228)
* tree-wide: Replace ZEND_STATIC_ASSERT() by static_assert()
* zend_portability: Remove ZEND_STATIC_ASSERT()
Changed paths:
M UPGRADING.INTERNALS
M Zend/zend_compile.c
M Zend/zend_compile.h
M Zend/zend_execute.h
M Zend/zend_portability.h
M ext/date/time_duration.c
M ext/random/engine_mt19937.c
M ext/random/php_random_zend_utils.h
Diff:
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 57e1ab63be8a..4b5eed39a7b5 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -16,6 +16,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES
- Removed zend_execute_scripts(). Manually call zend_execute_script() in a loop
instead.
+- Removed ZEND_STATIC_ASSERT(). Use C11 static_assert() directly instead.
========================
2. Build system changes
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index bad60a5f1071..8d65f1e91394 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5944,7 +5944,7 @@ static void zend_compile_static_var_common(zend_string *var_name, zval *value,
u
opline->op1_type = IS_CV;
opline->op1.var = lookup_cv(var_name);
- ZEND_STATIC_ASSERT(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in
lower three bits");
+ static_assert(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in
lower three bits");
opline->extended_value = (uint32_t)((char*)value -
(char*)CG(active_op_array)->static_variables->arData) | mode;
}
/* }}} */
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 6502770a2662..ec6d8b09bbe7 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -713,7 +713,7 @@ struct _zend_execute_data {
(call)->This.u2.num_args
/* Ensure the correct alignment before slots calculation */
-ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
+static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
"zval must be aligned by ZEND_MM_ALIGNMENT");
/* A number of call frame slots (zvals) reserved for zend_execute_data. */
#define ZEND_CALL_FRAME_SLOT \
diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h
index 2250a873af29..f7679d920d21 100644
--- a/Zend/zend_execute.h
+++ b/Zend/zend_execute.h
@@ -295,7 +295,7 @@ struct _zend_vm_stack {
};
/* Ensure the correct alignment before slots calculation */
-ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
+static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
"zval must be aligned by ZEND_MM_ALIGNMENT");
/* A number of call frame slots (zvals) reserved for _zend_vm_stack. */
#define ZEND_VM_STACK_HEADER_SLOTS \
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index 2e16a3683644..e6c7ed992b40 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -862,14 +862,6 @@ extern "C++" {
/** @deprecated */
#define ZEND_CGG_DIAGNOSTIC_IGNORED_END ZEND_DIAGNOSTIC_IGNORED_END
-#if defined(__cplusplus)
-# define ZEND_STATIC_ASSERT(c, m) static_assert((c), m)
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
-# define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m)
-#else
-# define ZEND_STATIC_ASSERT(c, m)
-#endif
-
#if !defined(ZEND_WIN32)
typedef max_align_t zend_max_align_t;
#else
diff --git a/ext/date/time_duration.c b/ext/date/time_duration.c
index a9f69db7a3d8..f84bee1fc72e 100644
--- a/ext/date/time_duration.c
+++ b/ext/date/time_duration.c
@@ -25,8 +25,8 @@
#define NANOS_IN_MILLI 1000000
#define MILLIS_IN_SEC 1000
-ZEND_STATIC_ASSERT(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, "");
-ZEND_STATIC_ASSERT(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, "");
+static_assert(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, "");
+static_assert(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, "");
#define Z_PARAM_ULONG(l) { \
zend_long __##l; \
diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c
index a84fb9585c80..bccf3770fb43 100644
--- a/ext/random/engine_mt19937.c
+++ b/ext/random/engine_mt19937.c
@@ -85,7 +85,7 @@
*/
#define N 624 /* length of state vector */
-ZEND_STATIC_ASSERT(
+static_assert(
N == sizeof(((php_random_status_state_mt19937*)0)->state) /
sizeof(((php_random_status_state_mt19937*)0)->state[0]),
"Assumed length of Mt19937 state vector does not match actual size."
);
diff --git a/ext/random/php_random_zend_utils.h b/ext/random/php_random_zend_utils.h
index 56718e5c214b..411da02a075c 100644
--- a/ext/random/php_random_zend_utils.h
+++ b/ext/random/php_random_zend_utils.h
@@ -25,7 +25,7 @@ typedef struct php_random_bytes_insecure_state_for_zend {
php_random_status_state_xoshiro256starstar xoshiro256starstar_state;
} php_random_bytes_insecure_state_for_zend;
-ZEND_STATIC_ASSERT(sizeof(zend_random_bytes_insecure_state) >=
sizeof(php_random_bytes_insecure_state_for_zend), "");
+static_assert(sizeof(zend_random_bytes_insecure_state) >=
sizeof(php_random_bytes_insecure_state_for_zend), "");
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_random_bytes_insecure_for_zend(
zend_random_bytes_insecure_state *state, void *bytes, size_t size);