Go to file
David Malcolm 26edace69b C/C++: more stdlib header hints (PR c/81404)
This patch extends the C frontend's "knowledge" of the C stdlib within
get_c_name_hint to cover some more macros and functions, covering
a case reported in PR c/81404 ("INT_MAX"), so that rather than printing:

  t.c:5:12: error: 'INT_MAX' undeclared here (not in a function); did you mean '__INT_MAX__'?
   int test = INT_MAX;
              ^~~~~~~
              __INT_MAX__

we instead print:

  t.c:5:12: error: 'INT_MAX' undeclared here (not in a function)
   int test = INT_MAX;
              ^~~~~~~
  t.c:5:12: note: 'INT_MAX' is defined in header '<limits.h>'; did you forget to '#include <limits.h>'?
  t.c:1:1:
  +#include <limits.h>

  t.c:5:12:
    int test = INT_MAX;
               ^~~~~~~

It also adds generalizes some of the code for this (and for the "std::"
namespace hints in the C++ frontend), moving it to a new
c-family/known-headers.cc and .h, and introducing a class known_headers.
This currently just works by scanning a hardcoded array of known
name/header associations, but perhaps in the future could be turned
into some kind of symbol database so that the compiler could record API
uses and use that to offer suggestions e.g.

foo.cc: error: 'myapi::foo' was not declared in this scope
foo.cc: note: 'myapi::foo" was declared in header 'myapi/private.h'
(included via 'myapi/public.h') when compiling 'bar.cc'; did you forget to
'#include "myapi/public.h"'?

or somesuch.

In any case, moving this to a class gives an easier way to locate the
hardcoded knowledge about the stdlib.

The patch also adds similar code to the C++ frontend covering
unqualified names in the standard library, so that rather than just
e.g.:

  t.cc:19:13: error: 'NULL' was not declared in this scope
   void *ptr = NULL;
               ^~~~

we can emit:

  t.cc:19:13: error: 'NULL' was not declared in this scope
   void *ptr = NULL;
               ^~~~
  t.cc:19:13: note: 'NULL' is defined in header '<cstddef>'; did you forget
  to '#include <cstddef>'?
  t.cc:1:1:
  +#include <cstddef>

  t.cc:19:13:
   void *ptr = NULL;
               ^~~~

(Also XFAIL for PR c++/80567 added for the C++ testcase; this is a
separate pre-existing bug exposed by the testcase for PR 81404).

gcc/ChangeLog:
	PR c/81404
	* Makefile.in (C_COMMON_OBJS): Add c-family/known-headers.o.

gcc/c-family/ChangeLog:
	PR c/81404
	* known-headers.cc: New file, based on material from c/c-decl.c.
	(suggest_missing_header): Copied as-is.
	(get_stdlib_header_for_name): New, based on get_c_name_hint but
	heavily edited to add C++ support.  Add some knowledge about
	<limits.h>, <stdint.h>, and <wchar.h>.
	* known-headers.h: Likewise.

gcc/c/ChangeLog:
	PR c/81404
	* c-decl.c: Include "c-family/known-headers.h".
	(get_c_name_hint): Rename to get_stdlib_header_for_name and move
	to known-headers.cc.
	(class suggest_missing_header): Move to known-header.h.
	(lookup_name_fuzzy): Call get_c_stdlib_header_for_name rather
	than get_c_name_hint.

gcc/cp/ChangeLog:
	PR c/81404
	* name-lookup.c: Include "c-family/known-headers.h"
	(lookup_name_fuzzy): Call get_cp_stdlib_header_for_name and
	potentially return a new suggest_missing_header hint.

gcc/testsuite/ChangeLog:
	PR c/81404
	* g++.dg/spellcheck-stdlib.C: New.
	* gcc.dg/spellcheck-stdlib.c (test_INT_MAX): New.

From-SVN: r254980
2017-11-21 00:50:39 +00:00
INSTALL
config Enable building libgcc with CET options. 2017-11-17 14:34:39 +01:00
contrib analyze_brprob.py: fix SI units 2017-11-08 07:24:14 +00:00
fixincludes fixinc.in (dirname): Change sed from 's|[^/]*/||' to 's|[^/]*//*||'. 2017-10-13 09:28:41 -06:00
gcc C/C++: more stdlib header hints (PR c/81404) 2017-11-21 00:50:39 +00:00
gnattools re PR ada/81878 (--disable-bootstrap --enable-languages=ada fails) 2017-08-17 13:39:58 +00:00
gotools Makefile.am (check-go-tool): Output colon after ${fl}. 2017-10-25 22:00:50 +00:00
include RISC-V: Implement __umulsidi3, umul_ppmm and __muluw3 2017-11-20 19:08:38 +00:00
intl Require ngettext in test of system gettext implementation 2017-11-07 15:24:01 +10:30
libada
libatomic Enable building libatomic with Intel CET 2017-11-17 22:18:15 +01:00
libbacktrace Enable building libbacktrace with Intel CET 2017-11-17 22:11:42 +01:00
libcc1 Makefile.am: Remove references to c-compiler-name.h and cp-compiler-name.h 2017-11-16 11:15:33 -07:00
libcilkrts
libcpp C++: provide macro used-before-defined hint (PR c++/72786) 2017-11-21 00:40:53 +00:00
libdecnumber
libffi Import from libffi master repository. 2017-10-03 14:26:31 -04:00
libgcc re PR bootstrap/83015 (bootstrap comparison failure on ia64) 2017-11-20 13:30:25 +01:00
libgfortran PR 44292 Handle large record lengths 2017-11-19 00:05:13 +02:00
libgo Adapt Solaris 12 references 2017-11-14 18:31:01 +00:00
libgomp Enable building libgomp with Intel CET 2017-11-17 22:22:09 +01:00
libhsail-rt [BRIGFE] Improved support for function and module scope group 2017-09-27 15:40:24 +00:00
libiberty re PR lto/82757 (r251560 causes: plugin needed to handle lto object) 2017-10-30 12:48:53 +00:00
libitm Enable building libitm with Intel CET 2017-11-17 23:59:41 +01:00
libmpx Enable building libmpx with Intel CET 2017-11-17 23:41:10 +01:00
libobjc Enable building libobjc with Intel CET 2017-11-17 23:48:36 +01:00
liboffloadmic
libquadmath Enable building libquadmath with Intel CET 2017-11-17 23:36:50 +01:00
libsanitizer Enable building libsanitizer with Intel CET 2017-11-17 22:34:50 +01:00
libssp Enable building libssp with Intel CET 2017-11-17 23:32:46 +01:00
libstdc++-v3 streambuf_iterator.h (istreambuf_iterator<>): Declare std::advance for istreambuf_iterator of char types to be friend. 2017-11-20 22:30:28 +00:00
libvtv Enable building libvtv with Intel CET 2017-11-17 23:29:19 +01:00
lto-plugin
maintainer-scripts update_version_svn: Ignore the GCC 5 branch. 2017-10-10 15:10:28 +02:00
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog RISC-V: Add Jim Wilson as a maintainer 2017-11-15 15:58:52 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
MAINTAINERS RISC-V: Add Jim Wilson as a maintainer 2017-11-15 15:58:52 +00:00
Makefile.def
Makefile.in Fix profiledbootstrap. 2017-10-27 13:13:05 +00:00
Makefile.tpl Fix profiledbootstrap. 2017-10-27 13:13:05 +00:00
README
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change
symlink-tree
ylwrap

README

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.