aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-07-14 15:09:00 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-07-14 15:09:00 +0000
commiteea77d1f3437366004a5d47efdf6b9cdbf3fcfbb (patch)
tree91bce65baf3294434588bd452b06ed508518e076 /gcc/c
parentbcf198440546aa583cf86ddce458a4bd26f616f0 (diff)
downloadgcc-eea77d1f3437366004a5d47efdf6b9cdbf3fcfbb.zip
gcc-eea77d1f3437366004a5d47efdf6b9cdbf3fcfbb.tar.gz
gcc-eea77d1f3437366004a5d47efdf6b9cdbf3fcfbb.tar.bz2
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
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog5
-rw-r--r--gcc/c/c-decl.c10
2 files changed, 13 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index aba0868..42ef9a5 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-14 David Malcolm <dmalcolm@redhat.com>
+
+ * c-decl.c (implicitly_declare): When suggesting a missing
+ #include, provide a fix-it hint.
+
2017-07-06 David Malcolm <dmalcolm@redhat.com>
* c-lang.c (selftest::run_c_tests): Move body to c_family_tests,
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 317d5cd..50da185 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -3386,8 +3386,14 @@ implicitly_declare (location_t loc, tree functionid)
const char *header
= header_for_builtin_fn (DECL_FUNCTION_CODE (decl));
if (header != NULL && warned)
- inform (loc, "include %qs or provide a declaration of %qD",
- header, decl);
+ {
+ rich_location richloc (line_table, loc);
+ maybe_add_include_fixit (&richloc, header);
+ inform_at_rich_loc
+ (&richloc,
+ "include %qs or provide a declaration of %qD",
+ header, decl);
+ }
newtype = TREE_TYPE (decl);
}
}