Bug #80617 [NEW]: GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE

From: Date: Mon, 11 Jan 2021 23:52:19 +0000
Subject: Bug #80617 [NEW]: GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231500@lists.php.net to get a copy of this message
From: nathanael at prolegis dot ca Operating system: Linux PHP version: 8.0.1 Package: Compile Warning Bug Type: Bug Bug description:GCC throws warning about type narrowing in ZEND_TYPE_INIT_CODE Description: ------------ When compiling a php extension with GCC we're getting a warning with gcc which is a fatal error with clang. When compiling we get the following warning/output: /usr/include/php/Zend/zend_types.h:264:50: warning: narrowing conversion of '((((12 == 17) ? ((1 << 2) | (1 << 3)) : ((12 == 16) ? (((((((((1 << 1) | (1 << 2)) | (1 << 3)) | (1 << 4)) | (1 << 5)) | (1 << 6)) | (1 << 7)) | (1 << 8)) | (1 << 9)) : (1 << 12))) | ((& arg)->Php::Argument::allowNull() ? 2 : 0)) | 0)' from 'int' to 'uint32_t {aka unsigned int}' inside { } [-Wnarrowing] | ((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) | (extra_flags)) ^ /usr/include/php/Zend/zend_types.h:260:11: note: in definition of macro 'ZEND_TYPE_INIT_MASK' { NULL, (_type_mask) } ^~~~~~~~~~ zend/callable.h:217:62: note: in expansion of macro 'ZEND_TYPE_INIT_CODE' case Type::Callable: info->type = (zend_type) ZEND_TYPE_INIT_CODE(IS_CALLABLE, arg.allowNull(), 0); break; // anything that can be invoke the issue is arg.allowNull() it returns an int, even though its 0 or 1 there's an the warning is there. If I just pass a 0, there is no warning. Another user commented as follows: https://github.com/CopernicaMarketingSoftware/PHP-CPP/pull/471#discussion_r553716780 Basically saying the issue was "The problem is because the zend_type struct takes a uint32_t, but they defined _ZEND_TYPE_NULLABLE_BIT as 0x2, and in C/C++ constants are signed by default. " Is this correct? If so can the _ZEND_TYPE_NULLABLE_BIT be defined as 0x2u instead? I've also tried casting the result of arg.allowNull to uint32_t to no avail. Test script: --------------- info->type = (zend_type) ZEND_TYPE_INIT_CODE(IS_UNDEF, arg.allowNull(), 0); Expected result: ---------------- No warnings about type narrowing when passing an int. -- Edit bug report at https://bugs.php.net/bug.php?id=80617&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80617&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80617&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80617&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80617&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80617&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80617&r=support Expected behavior: https://bugs.php.net/fix.php?id=80617&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80617&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80617&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80617&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80617&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80617&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80617&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80617&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80617&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80617&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80617&r=mysqlcfg

« previous php.bugs (#231500) next »