diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-08-27 14:02:05 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-08-27 14:02:05 +0000 |
commit | 85204e23e2fed09fc07159ab5607e0b760269561 (patch) | |
tree | 329a88e54e3b2d7854f2746bda51478b84b3e65e /gcc/cp | |
parent | df308f8160051f72679981d45ccbabe6b3f25396 (diff) | |
download | gcc-85204e23e2fed09fc07159ab5607e0b760269561.zip gcc-85204e23e2fed09fc07159ab5607e0b760269561.tar.gz gcc-85204e23e2fed09fc07159ab5607e0b760269561.tar.bz2 |
Less verbose fix-it hints for missing header files (PR 87091)
This patch tweaks maybe_add_include_fixit so that if we're emitting a note
about adding the header file, the note's primary location will be replaced
by that of the fix-it hint, to avoid repeating a location we've already
emitted (or one close to it).
For example, this simplifies:
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:22: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
....
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~
to:
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:27: error: msg 1
87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
eliminating the repetition of line 87 in the note.
Doing so requires converting show_caret_p to a tri-state, to avoid
meaninglessly printing a caret for the first column in the next line
(and colorizing it):
../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:74:1: note: msg 2
73 | # include <debug/vector>
+++ |+#include <vector>
74 | #endif
| ^
gcc/c-family/ChangeLog:
PR 87091
* c-common.c (c_cpp_error): Update for conversion of show_caret_p
to a tri-state.
(maybe_suggest_missing_token_insertion): Likewise.
(maybe_add_include_fixit): Add param "override_location". If set,
and source-printing is enabled, then override the rich_location's
primary location with that of the insertion point for the fix-it
hint, marking it with SHOW_LINES_WITHOUT_RANGE.
* c-common.h (extern void maybe_add_include_fixit): Add bool
param.
* c-format.c (selftest::test_type_mismatch_range_labels): Update
for conversion of show_caret_p to a tri-state.
* c-warn.c (warn_for_restrict): Likewise.
* known-headers.cc
(suggest_missing_header::~suggest_missing_header): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
gcc/c/ChangeLog:
PR 87091
* c-decl.c (implicitly_declare): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
* c-objc-common.c (c_tree_printer): Update for conversion of
show_caret_p to a tri-state.
gcc/cp/ChangeLog:
PR 87091
* decl.c (grokdeclarator): Update for conversion of show_caret_p
to a tri-state.
* error.c (cp_printer): Likewise.
* name-lookup.c (maybe_suggest_missing_std_header): Update call to
maybe_add_include_fixit to suggest overriding the location, as it
is for a note.
* parser.c (cp_parser_string_literal): Update for conversion of
show_caret_p to a tri-state.
(cp_parser_elaborated_type_specifier): Likewise.
(set_and_check_decl_spec_loc): Likewise.
* pt.c (listify): Update call to maybe_add_include_fixit to not
override the location, as it is for an error.
* rtti.c (typeid_ok_p): Likewise.
gcc/ChangeLog:
PR 87091
* diagnostic-show-locus.c (class layout_range): Update for
conversion of show_caret_p to a tri-state.
(layout_range::layout_range): Likewise.
(make_range): Likewise.
(layout::maybe_add_location_range): Likewise.
(layout::should_print_annotation_line_p): Don't show annotation
lines for ranges that are SHOW_LINES_WITHOUT_RANGE.
(layout::get_state_at_point): Update for conversion of
show_caret_p to a tri-state. Bail out early for
SHOW_LINES_WITHOUT_RANGE, so that such ranges don't affect
underlining or source colorization.
(gcc_rich_location::add_location_if_nearby): Update for conversion
of show_caret_p to a tri-state.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_labels): Likewise.
* gcc-rich-location.c (gcc_rich_location::add_expr): Update for
conversion of show_caret_p to a tri-state.
* pretty-print.c (text_info::set_location): Likewise.
* pretty-print.h (text_info::set_location): Likewise.
* substring-locations.c (format_warning_n_va): Likewise.
* tree-diagnostic.c (default_tree_printer): Likewise.
* tree-pretty-print.c (newline_and_indent): Likewise.
gcc/fortran/ChangeLog:
PR 87091
* error.c (gfc_format_decoder): Update for conversion of
show_caret_p to a tri-state.
gcc/testsuite/ChangeLog:
PR 87091
* gcc.dg/empty.h: New file.
* gcc.dg/fixits-pr84852-1.c: Update for move of fix-it hint to
top of file and removal of redundant second printing of warning
location.
* gcc.dg/fixits-pr84852-2.c: Likewise.
* gcc.dg/missing-header-fixit-3.c: Likewise.
* gcc.dg/missing-header-fixit-4.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Update for
conversion of show_caret_p to a tri-state.
libcpp/ChangeLog:
PR 87091
* include/line-map.h (enum range_display_kind): New enum.
(struct location_range): Replace field "m_show_caret_p" with
"m_range_display_kind", converting from bool to the new enum.
(class rich_location): Add example of line insertion fix-it hint.
(rich_location::add_range): Convert param "show_caret_p" from bool
to enum range_display_kind and rename to "range_display_kind",
giving it a default of SHOW_RANGE_WITHOUT_CARET.
(rich_location::set_range): Likewise, albeit without a default.
* line-map.c (rich_location::rich_location): Update for conversion
of show_caret_p to tri-state enum.
(rich_location::add_range): Likewise.
(rich_location::set_range): Likewise.
From-SVN: r263885
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/cp/error.c | 2 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 2 | ||||
-rw-r--r-- | gcc/cp/parser.c | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 2 | ||||
-rw-r--r-- | gcc/cp/rtti.c | 2 |
7 files changed, 29 insertions, 12 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e6d6208..a05049c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,20 @@ +2018-08-27 David Malcolm <dmalcolm@redhat.com> + + PR 87091 + * decl.c (grokdeclarator): Update for conversion of show_caret_p + to a tri-state. + * error.c (cp_printer): Likewise. + * name-lookup.c (maybe_suggest_missing_std_header): Update call to + maybe_add_include_fixit to suggest overriding the location, as it + is for a note. + * parser.c (cp_parser_string_literal): Update for conversion of + show_caret_p to a tri-state. + (cp_parser_elaborated_type_specifier): Likewise. + (set_and_check_decl_spec_loc): Likewise. + * pt.c (listify): Update call to maybe_add_include_fixit to not + override the location, as it is for an error. + * rtti.c (typeid_ok_p): Likewise. + 2018-08-27 Martin Liska <mliska@suse.cz> * call.c (build_call_a): Use new function diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c9c5fa6..d9f4d34 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10737,14 +10737,14 @@ grokdeclarator (const cp_declarator *declarator, if (signed_p && unsigned_p) { gcc_rich_location richloc (declspecs->locations[ds_signed]); - richloc.add_range (declspecs->locations[ds_unsigned], false); + richloc.add_range (declspecs->locations[ds_unsigned]); error_at (&richloc, "%<signed%> and %<unsigned%> specified together"); } else if (long_p && short_p) { gcc_rich_location richloc (declspecs->locations[ds_long]); - richloc.add_range (declspecs->locations[ds_short], false); + richloc.add_range (declspecs->locations[ds_short]); error_at (&richloc, "%<long%> and %<short%> specified together"); } else if (TREE_CODE (type) != INTEGER_TYPE @@ -10888,7 +10888,7 @@ grokdeclarator (const cp_declarator *declarator, if (staticp == 2) { gcc_rich_location richloc (declspecs->locations[ds_virtual]); - richloc.add_range (declspecs->locations[ds_storage_class], false); + richloc.add_range (declspecs->locations[ds_storage_class]); error_at (&richloc, "member %qD cannot be declared both %<virtual%> " "and %<static%>", dname); storage_class = sc_none; @@ -10897,7 +10897,7 @@ grokdeclarator (const cp_declarator *declarator, if (constexpr_p) { gcc_rich_location richloc (declspecs->locations[ds_virtual]); - richloc.add_range (declspecs->locations[ds_constexpr], false); + richloc.add_range (declspecs->locations[ds_constexpr]); error_at (&richloc, "member %qD cannot be declared both %<virtual%> " "and %<constexpr%>", dname); } @@ -11448,7 +11448,7 @@ grokdeclarator (const cp_declarator *declarator, { /* Cannot be both friend and virtual. */ gcc_rich_location richloc (declspecs->locations[ds_virtual]); - richloc.add_range (declspecs->locations[ds_friend], false); + richloc.add_range (declspecs->locations[ds_friend]); error_at (&richloc, "virtual functions cannot be friends"); friendp = 0; } diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 452ecb9..5bab3f3 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -4119,7 +4119,7 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec, pp_string (pp, result); if (set_locus && t != NULL) - text->set_location (0, location_of (t), true); + text->set_location (0, location_of (t), SHOW_RANGE_WITH_CARET); return true; #undef next_tree #undef next_tcode diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 8e009b2..c0a12d7 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5630,7 +5630,7 @@ maybe_suggest_missing_std_header (location_t location, tree name) if (cxx_dialect >= header_hint->min_dialect) { const char *header = header_hint->header; - maybe_add_include_fixit (&richloc, header); + maybe_add_include_fixit (&richloc, header, true); inform (&richloc, "%<std::%s%> is defined in header %qs;" " did you forget to %<#include %s%>?", diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 49d476b..d8d4301 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4133,7 +4133,7 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok, else if (curr_type != CPP_STRING) { rich_location rich_loc (line_table, tok->location); - rich_loc.add_range (last_tok_loc, false); + rich_loc.add_range (last_tok_loc); error_at (&rich_loc, "unsupported non-standard concatenation " "of string literals"); @@ -17755,7 +17755,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, || cp_parser_is_keyword (token, RID_STRUCT)) { gcc_rich_location richloc (token->location); - richloc.add_range (input_location, false); + richloc.add_range (input_location); richloc.add_fixit_remove (); pedwarn (&richloc, 0, "elaborated-type-specifier for " "a scoped enum must not use the %qD keyword", @@ -28390,7 +28390,7 @@ set_and_check_decl_spec_loc (cp_decl_specifier_seq *decl_specs, gcc_rich_location richloc (location); if (gnu != decl_specs->gnu_thread_keyword_p) { - richloc.add_range (decl_specs->locations[ds_thread], false); + richloc.add_range (decl_specs->locations[ds_thread]); error_at (&richloc, "both %<__thread%> and %<thread_local%> specified"); } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index efed9a1..a7266e3 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -26077,7 +26077,7 @@ listify (tree arg) if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list)) { gcc_rich_location richloc (input_location); - maybe_add_include_fixit (&richloc, "<initializer_list>"); + maybe_add_include_fixit (&richloc, "<initializer_list>", false); error_at (&richloc, "deducing from brace-enclosed initializer list" " requires %<#include <initializer_list>%>"); diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index 6692fb7..94a9219 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -317,7 +317,7 @@ typeid_ok_p (void) if (!COMPLETE_TYPE_P (const_type_info_type_node)) { gcc_rich_location richloc (input_location); - maybe_add_include_fixit (&richloc, "<typeinfo>"); + maybe_add_include_fixit (&richloc, "<typeinfo>", false); error_at (&richloc, "must %<#include <typeinfo>%> before using" " %<typeid%>"); |