[PATCH] c-family: Add fix-it suggestions for <stdlib.h> names [PR101052]

Martin Sebor msebor@gmail.com
Mon Jun 14 17:03:45 GMT 2021


On 6/14/21 6:17 AM, Jonathan Wakely via Gcc-patches wrote:
> 	PR c++/101052
> 
> gcc/c-family/ChangeLog:
> 
> 	* known-headers.cc (get_stdlib_header_for_name): Add known
> 	headers for EXIT_FAILURE, EXIT_SUCCESS, abort, atexit, calloc,
> 	exit, and getenv.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/spellcheck-stdlib.C: Add checks for <cstdlib> names.
> 	* gcc.dg/spellcheck-stdlib.c: Likewise.
> 
> There are no C tests for the functions because the C front-end doesn't
> give fix-it hints for them, it complains about mismatched implicit
> declarations. I assume this is why there were no existing tests for
> malloc, free, etc.
> 
> Tested powerpc64le-linux. OK for trunk?

A while back I noticed some other symbol wasn't giving a nice hint.
I think it was one of the <stdint.h> macros that I can never remember
if it's in <inttypes.h> or <limits.h>.  So decided to add them all,
and while I was there, I noticed that the function does a linear
search through the array.  That seems suboptimal so I started
optimizing it and never finished the work.

So I'm wondering if you stopped at the seven above for the same
reason or some other?

FWIW, I think the symbols that are hardcoded there now are some of
the most obvious ones.  The ones that are harder to remember tend
to be missing.  (E.g., I'd probably include <wchar.h> for wcstombs
and would have to look it up if I got an error.  YMMV of course.)

This is not an objection to adding just a handful of new names, just
a comment on the general state of incompleteness and the inefficient
data structure in case that matters.  If we don't care enough about
the inefficiency to avoid completing the list then I'd suggest to
add all the missing <stdlib.h> names, not just the seven above.

Martin


More information about the Gcc-patches mailing list