diff options
author | David Malcolm <dmalcolm@redhat.com> | 2017-07-14 15:09:00 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2017-07-14 15:09:00 +0000 |
commit | eea77d1f3437366004a5d47efdf6b9cdbf3fcfbb (patch) | |
tree | 91bce65baf3294434588bd452b06ed508518e076 /gcc/cp/rtti.c | |
parent | bcf198440546aa583cf86ddce458a4bd26f616f0 (diff) | |
download | gcc-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/cp/rtti.c')
-rw-r--r-- | gcc/cp/rtti.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index d73b1bc..a660cdd 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "stor-layout.h" #include "c-family/c-pragma.h" +#include "gcc-rich-location.h" /* C++ returns type information to the user in struct type_info objects. We also use type information to implement dynamic_cast and @@ -316,7 +317,12 @@ typeid_ok_p (void) if (!COMPLETE_TYPE_P (const_type_info_type_node)) { - error ("must %<#include <typeinfo>%> before using %<typeid%>"); + gcc_rich_location richloc (input_location); + maybe_add_include_fixit (&richloc, "<typeinfo>"); + error_at_rich_loc (&richloc, + "must %<#include <typeinfo>%> before using" + " %<typeid%>"); + return false; } |