From 5c6a2bf2720fd6412a2d63a3a82da5af0c18f824 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 16 Aug 2018 22:33:00 +0000 Subject: diagnostics: fix bad interaction between line spans and line numbers Without this patch, the "line span" markers and the line numbering interacted badly, leading to stray copies of the line-span markers appearing as prefixes on the first source line in a span: missing-header-fixit-3.c: In function 'test': missing-header-fixit-3.c:9:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 9 | printf ("%i of %i\n", i, j); | ^~~~~~ missing-header-fixit-3.c:9:3: warning: incompatible implicit declaration of built-in function 'printf' missing-header-fixit-3.c:9:3: note: include '' or provide a declaration of 'printf' missing-header-fixit-3.c:1:1: |+#include missing-header-fixit-3.c:1:1:1 | /* Example of a fix-it hint that adds a #include directive, missing-header-fixit-3.c:9:3: missing-header-fixit-3.c:9:3:9 | printf ("%i of %i\n", i, j); | ^~~~~~ With this patch, we now correctly print: missing-header-fixit-3.c: In function 'test': missing-header-fixit-3.c:9:3: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 9 | printf ("%i of %i\n", i, j); | ^~~~~~ missing-header-fixit-3.c:9:3: warning: incompatible implicit declaration of built-in function 'printf' missing-header-fixit-3.c:9:3: note: include '' or provide a declaration of 'printf' missing-header-fixit-3.c:1:1: + |+#include 1 | /* Example of a fix-it hint that adds a #include directive, missing-header-fixit-3.c:9:3: 9 | printf ("%i of %i\n", i, j); | ^~~~~~ gcc/ChangeLog: * diagnostic.c (default_diagnostic_start_span_fn): Call pp_string to emit the span, rather than setting it as the prefix. gcc/testsuite/ChangeLog: * gcc.dg/missing-header-fixit-3.c: New test. From-SVN: r263606 --- gcc/diagnostic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gcc/diagnostic.c') diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 59477ce..7e8bcf5 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -629,9 +629,9 @@ void default_diagnostic_start_span_fn (diagnostic_context *context, expanded_location exploc) { - pp_set_prefix (context->printer, - diagnostic_get_location_text (context, exploc)); - pp_string (context->printer, ""); + char *text = diagnostic_get_location_text (context, exploc); + pp_string (context->printer, text); + free (text); pp_newline (context->printer); } -- cgit v1.1