-Wdiscarded-qualifiers warning in _ctypes_test.c my_strchr() under FORTIFY_SOURCE=3 #149707
Copy link
Copy link
Closed
Closed
Copy link
Labels
buildThe build process and cross-buildThe build process and cross-buildextension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Building 3.14.5 with gcc 15.2 and --enable-slower-safety produces this warning:
default: ./Modules/_ctypes/_ctypes_test.c: In function ‘my_strchr’:
default: ./Modules/_ctypes/_ctypes_test.c:451:12: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
default: 451 | return strchr(s, c);
default: | ^~~~~~
Build environment: Ubuntu 26.04 LTS, gcc 15.2.0, configure with:
./configure --enable-optimizations --with-lto --enable-bolt --enable-safety --enable-slower-safety --with-system-expat CXX=/usr/bin/g++ CFLAGS="-flto=auto" LDFLAGS="-flto=auto"CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-149707: Fix compiler warning in _ctypes_test on strchr() #149791
- [3.15] gh-149707: Fix compiler warning in _ctypes_test on strchr() (GH-149791) #149862
- [3.14] gh-149707: Fix compiler warning in _ctypes_test on strchr() (GH-149791) #149863
- [3.13] gh-149707: Fix compiler warning in _ctypes_test on strchr() (GH-149791) #149864
- [3.15] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) #149865
- [3.14] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) #149866
- [3.13] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791) #149867
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
buildThe build process and cross-buildThe build process and cross-buildextension-modulesC modules in the Modules dirC modules in the Modules dirtestsTests in the Lib/test dirTests in the Lib/test dirtopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
gh-149707: Fix compiler warning in _ctypes_test on strchr() (#149791)
vstinner commentedon May 15, 2026
On Linux with the glibc, when using C23,
strchr(text, ch)return type isconst char*if text type isconst char*.See for example the glibc commit which introduced C23 support in
string/string.h.The
string.hcode is now:pythongh-149707: Fix compiler warning in _ctypes_test on strchr() (py…
pythongh-149707: Fix compiler warning in _ctypes_test on strchr() (py…
[3.13] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#…
[3.14] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#…
[3.15] gh-149707: Fix compiler warning in _ctypes_test on strchr() (#…