+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
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 ()));
}
{
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
+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
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^
i = z.i;
} // { dg-warning "no return statement in function returning non-void" }
/* { dg-begin-multiline-output "" }
+ i = z.i;
+ return *this;
}
^