diagnostics: show an extra line of context in line-insertion fix-it hints (PR 87091)
commite69492e42588e41cfbaa8cce0ba8623815e18b8f
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Aug 2018 13:46:32 +0000 (27 13:46 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Aug 2018 13:46:32 +0000 (27 13:46 +0000)
tree28d1a7f90410f9f92679a6260c322d0dc2d61070
parent64f41321804f68ba44d9c00920bd2069b9f02d89
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263884 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/diagnostic-show-locus.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr85523.C
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c