Hi, On Fri, Jul 05, 2024 at 06:30:50PM GMT, Martin Uecker wrote: > Am Freitag, dem 05.07.2024 um 17:24 +0100 schrieb Jonathan Wakely: > > On Fri, 5 Jul 2024 at 17:02, Xi Ruoyao via Gcc <gcc@xxxxxxxxxxx> wrote: > > > > > > On Fri, 2024-07-05 at 17:53 +0200, Alejandro Colomar wrote: > > > > At least, I hope there's consensus that while current GCC doesn't warn > > > > about this, ideally it should, which means it should warn for valid uses > > > > of strtol(3), which means strtol(3) should be fixed, in all of ISO, > > > > POSIX, and glibc. > > > > > > It **shouldn't**. strtol will only violate restrict if it's wrongly > > > implemented, or something dumb is done like "strtol((const char*) &p, > > > &p, 0)". > > > > > > See my previous reply. That's not right. See my reply to yours, Xi. The restrict in char **endptr already prevents calls such as strtol(x, x, 0). The restrict in const char *nptr provides nothing. > > > > Right, is there a valid use of strtol where a warning would be justified? Is there any valid reason to have restrict in the _first_ parameter of strtol(3)? Other than "ISO C says so"? I'll take my beef with ISO C to WG14, and hopefully get that fixed. Can we please discuss this technically, ignoring the existence of ISO C, for the time being? > > Showing that you can contrive a case where a const char* restrict and > > char** restrict can alias doesn't mean there's a problem with strtol. > > I think his point is that a const char* restrict and something which > is stored in a char* whose address is then passed can alias and there > a warning would make sense in other situations. Indeed. > But I am also not convinced removing restrict would be an improvement. > It would make more sense to have an annotation that indicates that > endptr is only used as output. What is the benefit of keeping restrict there? It doesn't provide any benefits, AFAICS. I've prepared a paper for wg14. I'll ask for a number, but will attach it here already. I also attach the man(7) source code for it. Cheers, Alex -- <https://www.alejandro-colomar.es/>
Attachment:
strtol.man
Description: Unix manual page
Attachment:
strtol.pdf
Description: Adobe PDF document
Attachment:
signature.asc
Description: PGP signature