C: hints for missing stdlib includes for macros and types
The C frontend already "knows" about many common functions in the C standard library: test.c: In function 'test': test.c:3:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] printf ("hello world\n"); ^~~~~~ test.c:3:3: warning: incompatible implicit declaration of built-in function 'printf' test.c:3:3: note: include '<stdio.h>' or provide a declaration of 'printf' and which header file they are in. However it doesn't know about various types and macros: test.c:1:13: error: 'NULL' undeclared here (not in a function) void *ptr = NULL; ^~~~ This patch uses the name_hint/deferred_diagnostic machinery to add hints for missing C standard library headers for some of the most common type and macro names. For example, the above becomes: test.c:1:13: error: 'NULL' undeclared here (not in a function) void *ptr = NULL; ^~~~ test.c:1:13: note: 'NULL' is defined in header '<stddef.h>'; did you forget to '#include <stddef.h>'? gcc/c/ChangeLog: * c-decl.c (get_c_name_hint): New function. (class suggest_missing_header): New class. (lookup_name_fuzzy): Call get_c_name_hint and use it to suggest missing headers to the user. gcc/testsuite/ChangeLog: * gcc.dg/spellcheck-stdlib.c: New test case. From-SVN: r254979
Showing
gcc/testsuite/gcc.dg/spellcheck-stdlib.c
0 → 100644
Please
register
or
sign in
to comment