[php-src] PHP-8.6: Fix GH-25023: ZEND_CONTAINER_OF() fails to compile with -std=c11 (#25027)
| From: | Lazizbek Ergashev via GitHub | Date: | Thu, 29 Oct 2026 09:26:45 +0000 |
| Subject: | [php-src] PHP-8.6: Fix GH-25023: ZEND_CONTAINER_OF() fails to compile with -std=c11 (#25027) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142927@lists.php.net to get a copy of this message | ||
Author: Lazizbek Ergashev (lazerg)
Committer: GitHub (web-flow)
Pusher: arnaud-lb
Date: 2026-10-29T10:26:41+01:00
Commit: https://github.com/php/php-src/commit/e5e5a8a9d20df13d7d4d464af11c8422b6797cbe
Raw diff: https://github.com/php/php-src/commit/e5e5a8a9d20df13d7d4d464af11c8422b6797cbe.diff
Fix GH-25023: ZEND_CONTAINER_OF() fails to compile with -std=c11 (#25027)
Changed paths:
M NEWS
M Zend/zend_portability.h
Diff:
diff --git a/NEWS b/NEWS
index bf0ae375324f..6899e0b14e81 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP NEWS
for grouping. (Klaas Skelte van der Werf)
. Fixed unmapping of an unrelated range when the aligned chunk mmap fails
(Marti2203).
+ . Fixed bug GH-25023 (ZEND_CONTAINER_OF() fails to compile with -std=c11).
+ (lazerg)
- CLI:
. Fixed bug GH-24697 (PHP_HTTP_PARSER_STRICT build option doesn't work).
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index ccad24682fdb..3549fe6f544b 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -387,6 +387,12 @@ char *alloca();
#define ZEND_ELEMENT_COUNT(m)
#endif
+#if __STDC_VERSION__ >= 202311L
+# define ZEND_TYPEOF(x) typeof(x)
+#elif ZEND_GCC_VERSION
+# define ZEND_TYPEOF(x) __typeof__(x)
+#endif
+
#if __cplusplus
extern "C++" {
# include <cstddef>
@@ -401,13 +407,12 @@ extern "C++" {
# define ZEND_CONTAINER_OF(ptr, Type, member) zend_container_of<Type,
decltype(Type::member)>(ptr, offsetof(Type, member))
}
-#elif __STDC_VERSION__ >= 202311L || ZEND_GCC_VERSION
-/* typeof is C23 or a GCC extension */
+#elif defined(ZEND_TYPEOF)
# define ZEND_CONTAINER_OF(ptr, Type, member) \
_Generic( \
(ptr), \
- const typeof(((Type*)0)->member) *: ((const Type*)((char*)(ptr) - offsetof(Type, member))), \
- typeof(((Type*)0)->member) *: ((Type*)((char*)(ptr) - offsetof(Type, member))) \
+ const ZEND_TYPEOF(((Type*)0)->member) *: ((const Type*)((char*)(ptr) - offsetof(Type,
member))), \
+ ZEND_TYPEOF(((Type*)0)->member) *: ((Type*)((char*)(ptr) - offsetof(Type, member))) \
)
#else
/* Define a variant that does not keep const-ness for older compilers. Mismatches