|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40683 zend_operators.h generates discard qualifier compiler warning
Submitted: 2007-03-01 19:44 UTC Modified: 2007-03-12 09:29 UTC
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: lstefani at fortresstech dot com Assigned:
Status: Wont fix Package: Compile Warning
PHP Version: 5.2.1 OS: linux 2.6.12-1.1381_FC3smp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: lstefani at fortresstech dot com
New email:
PHP Version: OS:


 [2007-03-01 19:44 UTC] lstefani at fortresstech dot com
Zend/zend_operators.h: In function `void* zend_memrchr(const void*, int, unsigned int)':
Zend/zend_operators.h:250: warning: cast from `const void*' to `unsigned char*' discards qualifiers from pointer target type
Zend/zend_operators.h:250: warning: cast from `const void*' to `unsigned char*' discards qualifiers from pointer target type

In code snippet, line 250 refers to the two recasts of argument s.

Reproduce code:
static inline void *zend_memrchr(const void *s, int c, size_t n)
  register unsigned char *e;

  if (n <= 0) {
    return NULL;

  for (e = (unsigned char *)s + n - 1; e >= (unsigned char *)s; e--) {
    if (*e == (unsigned char)c) {
      return (void *)e;

  return NULL;

Expected result:
No compiler warnings.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-01 19:59 UTC]
What compiler do you use?
 [2007-03-09 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-03-12 00:08 UTC] lstefani at fortresstech dot com
Sorry for the late response.  Your email hit my company spam filter for some reason.  Just found it while going through the bulk mail folder.

To answer your question, I'm using the MIPS cross-compiler (GCC 3.3.2 and GLIBC 2.3.2) on Linux x86.  I know that's not the latest GCC compiler by a long shot, but just from reviewing the code, it does appear that the const declaration is being discarded by recasting the parameter as an unsigned char.
 [2007-03-12 09:29 UTC]
You can safely ignore it.
And no, I can't reproduce this warning with GCC4 & GCC3.4.6 or any other compiler.
 [2021-11-22 14:22 UTC] dennis dot buteyn at xorcom dot com
Would like someone to reopen this bug if possible, it is preventing me from using -Werror compiler flag. Have seen this warning while compiling for both PHP 5 and PHP 7 without fail. Here is part of the build log when cross-compiling to arm64 in a Debian 11 Docker container.

libtool: compile:  aarch64-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -Wshadow -pedantic -fPIC -fno-rtti -std=c++14 -flto -ffunction-sections -fdata-sections -g -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -Wno-unused -Wno-unused-parameter -c plugin.cpp  -fPIC -DPIC -o src/.libs/plugin.o

In file included from /usr/include/php/20190902/Zend/zend.h:356,
                 from /usr/include/php/20190902/main/php.h:34,
                 from src/ombu_xlic.cpp:2:
/usr/include/php/20190902/Zend/zend_operators.h: In function 'const void* zend_memrchr(const void*, int, size_t)':
/usr/include/php/20190902/Zend/zend_operators.h:197:13: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
  197 |   if (*e == (const unsigned char)c) {
      |             ^~~~~~~~~~~~~~~~~~~~~~
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 03:01:29 2024 UTC