Heads up: new const warnings from strchr with gcc 16
Hal Murray
halmurray at sonic.net
Thu Mar 12 03:24:12 UTC 2026
Fedora 44-Alpha is out. It's got gcc 16 which is now "smart" enough to
generate a new warning.
This is what I think is going on:
Here is the prototype for strchr:
char *strchr(const char *s, int c);
If you pass in a non-const string, that's OK. strchr promises not to
modify it.
If you pass in a const string, the compiler figures out that the answer is
pointing into that string so the result should really be a const.
I fixed a few simple cases. I haven't fixed this one.gcc
../../ntpd/refclock_oncore.c: In function "oncore_msg_Cj_id":
../../ntpd/refclock_oncore.c:2946:29: error: initialization discards
"const" qualifier from pointer target type [-Werror=discarded-qualifiers]
2946 | char *cpw = strchr(cp, '\r');
| ^~~~~~
cc1: all warnings being treated as errors
If you have a fix but don't have access to the new gcc, send me the diff
or make an MR and I will test it.
gcc version 16.0.1 20260305 (Red Hat 16.0.1-0) (GCC)
--
These are my opinions. I hate spam.
More information about the devel
mailing list