aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-08-27 13:46:32 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-08-27 13:46:32 +0000
commitdf308f8160051f72679981d45ccbabe6b3f25396 (patch)
tree28d1a7f90410f9f92679a6260c322d0dc2d61070 /gcc
parent47c3496bf898e9dfe12799ef6e31ae9b9211c63d (diff)
downloadgcc-df308f8160051f72679981d45ccbabe6b3f25396.zip
gcc-df308f8160051f72679981d45ccbabe6b3f25396.tar.gz
gcc-df308f8160051f72679981d45ccbabe6b3f25396.tar.bz2
diagnostics: show an extra line of context in line-insertion fix-it hints (PR 87091)
This patch tweaks how we print line-insertion fix-it hints, so that the line before the insertion point is also printed, to give the user more context on the proposed change. For example, it changes: ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:22: note: message +++ |+#include <vector> 74 | #endif .... 87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; | ^~~ to: ../x86_64-pc-linux-gnu/libstdc++-v3/include/vector:87:22: note: message 73 | # include <debug/vector> +++ |+#include <vector> 74 | #endif .... 87 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; | ^~~ gcc/ChangeLog: PR 87091 * diagnostic-show-locus.c (get_line_span_for_fixit_hint): Show the line above for line-insertion fix-it hints. (selftest::test_fixit_insert_containing_newline): Update the expected results, and add a test with line-numbering enabled. gcc/testsuite/ChangeLog: PR 87091 * g++.dg/pr85523.C: Extend expected output to show line before line-insertion fix-it hint. * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c (test_fixit_insert_newline): Add previous line to expected output. * gcc.dg/plugin/diagnostic-test-show-locus-bw.c: Likewise. * gcc.dg/plugin/diagnostic-test-show-locus-color.c: Likewise. From-SVN: r263884
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/diagnostic-show-locus.c43
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/g++.dg/pr85523.C3
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c1
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c1
-rw-r--r--gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c1
7 files changed, 59 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6a04712..f3ee5cf 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-08-27 David Malcolm <dmalcolm@redhat.com>
+
+ PR 87091
+ * diagnostic-show-locus.c (get_line_span_for_fixit_hint): Show the
+ line above for line-insertion fix-it hints.
+ (selftest::test_fixit_insert_containing_newline): Update the
+ expected results, and add a test with line-numbering enabled.
+
2018-08-27 Martin Liska <mliska@suse.cz>
PR sanitizer/86962
diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c
index 1e7f969..d305ada 100644
--- a/gcc/diagnostic-show-locus.c
+++ b/gcc/diagnostic-show-locus.c
@@ -1159,7 +1159,16 @@ static line_span
get_line_span_for_fixit_hint (const fixit_hint *hint)
{
gcc_assert (hint);
- return line_span (LOCATION_LINE (hint->get_start_loc ()),
+
+ int start_line = LOCATION_LINE (hint->get_start_loc ());
+
+ /* For line-insertion fix-it hints, add the previous line to the
+ span, to give the user more context on the proposed change. */
+ if (hint->ends_with_newline_p ())
+ if (start_line > 1)
+ start_line--;
+
+ return line_span (start_line,
LOCATION_LINE (hint->get_next_loc ()));
}
@@ -3479,13 +3488,31 @@ test_fixit_insert_containing_newline (const line_table_case &case_)
{
rich_location richloc (line_table, case_loc);
richloc.add_fixit_insert_before (line_start, " break;\n");
- test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
- ASSERT_STREQ ("\n"
- "+ break;\n"
- " case 'b':\n"
- " ^~~~~~~~~\n",
- pp_formatted_text (dc.printer));
+
+ /* Without line numbers. */
+ {
+ test_diagnostic_context dc;
+ diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ ASSERT_STREQ ("\n"
+ " x = a;\n"
+ "+ break;\n"
+ " case 'b':\n"
+ " ^~~~~~~~~\n",
+ pp_formatted_text (dc.printer));
+ }
+
+ /* With line numbers. */
+ {
+ test_diagnostic_context dc;
+ dc.show_line_numbers_p = true;
+ diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ ASSERT_STREQ ("\n"
+ "2 | x = a;\n"
+ "+ |+ break;\n"
+ "3 | case 'b':\n"
+ " | ^~~~~~~~~\n",
+ pp_formatted_text (dc.printer));
+ }
}
/* Verify that attempts to add text with a newline fail when the
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4f49ffd..24e2047 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-27 David Malcolm <dmalcolm@redhat.com>
+
+ PR 87091
+ * g++.dg/pr85523.C: Extend expected output to show line
+ before line-insertion fix-it hint.
+ * gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
+ (test_fixit_insert_newline): Add previous line to expected output.
+ * gcc.dg/plugin/diagnostic-test-show-locus-bw.c: Likewise.
+ * gcc.dg/plugin/diagnostic-test-show-locus-color.c: Likewise.
+
2018-08-27 Martin Liska <mliska@suse.cz>
PR sanitizer/86962
diff --git a/gcc/testsuite/g++.dg/pr85523.C b/gcc/testsuite/g++.dg/pr85523.C
index 9cd939b..0ed16ff 100644
--- a/gcc/testsuite/g++.dg/pr85523.C
+++ b/gcc/testsuite/g++.dg/pr85523.C
@@ -47,6 +47,7 @@ struct s5 {
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^
@@ -63,6 +64,7 @@ struct s6 {
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^
@@ -81,6 +83,7 @@ struct s7 {
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
index f2bbc58..63e5855 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
@@ -111,6 +111,7 @@ void test_fixit_insert_newline (void)
x = b;
}
/* { dg-begin-multiline-output "" }
+109 | x = a;
+++ |+ break;
110 | case 'b':
| ^~~~~~~~
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
index bdfa420..be6f103 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
@@ -332,6 +332,7 @@ void test_fixit_insert_newline (void)
x = b;
}
/* { dg-begin-multiline-output "" }
+ x = a;
+ break;
case 'b':
^~~~~~~~
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c
index 094bc65..7ae3801 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c
@@ -217,6 +217,7 @@ void test_fixit_insert_newline (void)
x = b;
}
/* { dg-begin-multiline-output "" }
+ x = a;
+ break;
case 'b':
^~~~~~~~