[php-src] Issue #25023: ZEND_CONTAINER_OF() uses typeof, which GCC rejects in strict ISO mode (-std=c11/-std=c17)
| From: | mlocati | Date: | Wed, 28 Oct 2026 23:39:09 +0000 |
| Subject: | [php-src] Issue #25023: ZEND_CONTAINER_OF() uses typeof, which GCC rejects in strict ISO mode (-std=c11/-std=c17) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253909@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25023
Author: mlocati
### Description
ZEND_CONTAINER_OF() (added in #21903) is defined as follows in
Zend/zend_portability.h:
```c
#elif __STDC_VERSION__ >= 202311L || ZEND_GCC_VERSION
/* typeof is C23 or a GCC extension */
# 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))) \
)
```
With GCC, the typeof spelling of the extension is only available in GNU mode
(-std=gnuXX, the default).
In strict ISO mode before C23 (-std=c11, -std=c17) GCC only accepts
__typeof__, so the ZEND_GCC_VERSION branch fails to compile.
The same header already uses the always-available spelling in ZEND_IGNORE_VALUE()
(__typeof__).
Since ZEND_CONTAINER_OF() is now used in public extension headers
(ext/pdo/php_pdo_driver.h, ext/date/php_date.h,
ext/dom/xml_common.h, ext/simplexml/php_simplexml_exports.h,
ext/uri/php_uri_common.h), any third-party extension built with -std=c11
no longer compiles against PHP 8.6.
A real-world example is pdo_snowflake, whose config.m4 sets CFLAGS="-std=c11
-Werror $CFLAGS".
The following code (t.c):
```c
#include <php.h>
#include <ext/pdo/php_pdo_driver.h>
int main(void) { return 0; }
```
Compiled with:
```sh
gcc -std=c11 $(php-config --includes) -c t.c
```
Resulted in this output (GCC 15.2.0):
```
/usr/local/include/php/ext/pdo/php_pdo_driver.h: In function 'php_pdo_dbh_fetch_inner':
/usr/local/include/php/Zend/zend_portability.h:409:23: error: unknown type name 'typeof'
409 | const typeof(((Type*)0)->member) *: ((const Type*)((char*)(ptr) -
offsetof(Type, member))), \
| ^~~~~~
/usr/local/include/php/ext/pdo/php_pdo_driver.h:521:31: note: in expansion of macro
'ZEND_CONTAINER_OF'
521 | return (pdo_dbh_t *)((ZEND_CONTAINER_OF(obj, pdo_dbh_object_t, std))->inner);
| ^~~~~~~~~~~~~~~~~
```
But I expected it to compile, as it does with -std=gnu11 and with
-std=c23.
Replacing typeof with __typeof__ in the two lines above fixes the build
with -std=c11 and keeps it working with -std=c23 (verified by patching the
installed header).
The problem is also present on master.
### PHP Version
```plain
PHP 8.6.0RC4 (cli) (built: Oct 21 2026 22:48:58) (ZTS)
Copyright © The PHP Group and Contributors
Built by https://github.com/docker-library/php
Zend Engine v4.6.0RC4, Copyright © Zend by Perforce
with Zend OPcache v8.6.0RC4, Copyright ©, by Zend by Perforce
```
### Operating System
Alpine Linux 3.23 (Docker image php:8.6-rc-cli-alpine), GCC 15.2.0