Re: setlocale: Silence a -Wdiscarded-qualifiers warning on Windows.
Alejandro Colomar <[email protected]>
| Newsgroups | gmane.comp.lib.gnulib.bugs |
|---|---|
| Message-ID | <aiYBC-IqomJ96Pcy@devuan> |
Hi Bruno, Collin, On 2026-06-07T21:35:07+0200, Bruno Haible wrote: > Collin Funk wrote: > > > But we can add the intended return type in Gnulib. Done as follows. This > > > patch removes two casts, instead of adding a cast. > > > > I considered suggesting this as well for the same reason you mention, > > i.e., the standard saying the returned string cannot be modified. But I > > mistakenly assumed you would not want to diverge from the standardized > > prototype. > > We had some (conditional) change of return type from 'char *' to 'const char *', > or from 'void *' to 'const void *', in functions like strchr and memchr, > and although it was a bit of a hassle for the people who maintain very old > packages, it was a worthwhile modernization. > > In POSIX, the following functions are marked with > "The application shall not modify the string returned." > and could therefore be modernized: > ctermid > dlerror > getgrent > getgrgid, getgrnam > gethostent > getlogin > getnetent, getnetbyaddr, getnetbyname > getprotoent, getprotobyname, getprotobynumber > getpwent, getpwnam, getpwuid > getservent, getservbyname, getservbyport > localeconv > nl_langinfo, nl_langinfo_l > ptsname > setlocale > strerror, strerror_l > strsignal > ttyname > *gettext, *gettext_l Of which, the following are in ISO C: localeconv setlocale strerror > > I vaguely remember > > POSIX being willing to change the return type of gettext to be "const > > char *" for similar reasons > > That would be useful too, yes. > > > Perhaps it is worth bringing this up with the ISO C people. > > Yes, that would be useful, both for setlocale() and for localeconv(). I will mention within the committee that now that we've changed the prototypes of string APIs --thus accepting breaking changes--, we could embrace the const-correctness even further by changing the return types of those functions too. Thanks for the suggestion! And indeed, I agree that changing the return values of those functions is a good idea, as a gnulib extension (and hopefully also in the standards). I've reviewed 8724b4400aac (2026-06-07; "setlocale: Detect invalid writes to the returned string in some cases."), and it LGTM. Thanks! Should I also have a look at anything else from this thread? Have a lovely night! Alex > > Bruno -- <https://www.alejandro-colomar.es>
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmomBMkACgkQ64mZXMKQ wqkz1xAAnFFFIVzdO6zuFrGef0pGyyU3D+TGd3GovBeMK+v9NcZihMvXxEaBAyq1 A8XMkaVscCT3vSotrwvOLQOgS1avUCRDZOWQoc8jw3OIGl08FoRxSiyV1x/DhzOS Xop7ezqleX9dVCx3xW02aHetH9ksTGFbgy/sjIdr+lAhcKG0NgG/RUN7PQ6++Tns 9U86m61NWN5+at6yUrOAo3aDrQ8AmQhmKzLCblIIRagLWVtMZDv5U/4hezB38jY+ KMXydpRlnGFfS9iCPVhoPoftPPBpZUnvtHp3qLjfrgRFv9G5TZDWMeNMxKcc0TuY a8dLh0mm6LlUC+GNAwKElkyU2bk7+6rVQWpkC2UA66mdFE9P5t3BYx0UPpsgPUEF pDC1Wf6tK7uBdHMB+/Rtoi2ekzuMyLmjkVEVl64Uk636c/7Sl003bLCiuhJ+J/8p TvvajcTbLLGLM+J3lkAPWZ00BOMkq62SuRK9DtWZroxfpbLqgDMb+e9oU7mNPoIT E6W6zfP2yOYz1oWIAAoJP5cKMgzDmfuiBFp+61VUBg3bXQVZeL7UzgcIvFfk87NN 0l6yVDI4QteEZZdJcmYND6LZetQ1zNn8mP9SIh+I8U+J2tvFkV5Runo2lreKoaXX vh5wlb6pBVzZ1Zl/Mkr86QaKS+ZxdkqXpn7PwcQa3tiGFr+7+bo= =EZLk -----END PGP SIGNATURE-----