c/c++: Add fix-it hints for suggested missing #includes
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 14 Jul 2017 15:09:00 +0000 (15:09 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Fri, 14 Jul 2017 15:09:00 +0000 (15:09 +0000)
commiteea77d1f3437366004a5d47efdf6b9cdbf3fcfbb
tree91bce65baf3294434588bd452b06ed508518e076
parentbcf198440546aa583cf86ddce458a4bd26f616f0
c/c++: Add fix-it hints for suggested missing #includes

gcc/c-family/ChangeLog:
* c-common.c (try_to_locate_new_include_insertion_point): New
function.
(per_file_includes_t): New typedef.
(added_includes_t): New typedef.
(added_includes): New variable.
(maybe_add_include_fixit): New function.
* c-common.h (maybe_add_include_fixit): New decl.

gcc/c/ChangeLog:
* c-decl.c (implicitly_declare): When suggesting a missing
#include, provide a fix-it hint.

gcc/cp/ChangeLog:
* name-lookup.c (get_std_name_hint): Add '<' and '>' around
the header names.
(maybe_suggest_missing_header): Update for addition of '<' and '>'
to above.  Provide a fix-it hint.
* pt.c: Include "gcc-rich-location.h"
(listify): Attempt to add fix-it hint for missing
#include <initializer_list>.
* rtti.c: Include "gcc-rich-location.h".
(typeid_ok_p): Attempt to add fix-it hint for missing
#include <typeinfo>.

gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/missing-initializer_list-include.C: New test case.
* g++.dg/lookup/missing-std-include-2.C: New test case.
* g++.dg/lookup/missing-std-include-3.C: New test case.
* g++.dg/rtti/missing-typeinfo-include.C: New test case.
* gcc.dg/missing-header-fixit-1.c: New test case.
* gcc.dg/missing-header-fixit-2.c: New test case.
* gcc.dg/missing-header-fixit-2.h: New header.

From-SVN: r250203
17 files changed:
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/cp/pt.c
gcc/cp/rtti.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/missing-initializer_list-include.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/missing-std-include-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/missing-std-include-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/rtti/missing-typeinfo-include.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/missing-header-fixit-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/missing-header-fixit-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/missing-header-fixit-2.h [new file with mode: 0644]