diagnostics: fix bad interaction between line spans and line numbers
commit287abdae0183091515b3ba62250866c6c9de379d
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Aug 2018 22:33:00 +0000 (16 22:33 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 Aug 2018 22:33:00 +0000 (16 22:33 +0000)
tree8288ba2c095a7579fae973b7e47977f8190e81d2
parent87c50f508acf5301d02fa38afa1709742a2b4d7d
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 '<stdio.h>' or provide a declaration of 'printf'
missing-header-fixit-3.c:1:1:
  |+#include <stdio.h>
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 '<stdio.h>' or provide a declaration of 'printf'
missing-header-fixit-3.c:1:1:
+ |+#include <stdio.h>
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263606 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/diagnostic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/missing-header-fixit-3.c [new file with mode: 0644]