The following patch kit adds experimental support for nested
diagnostics to g++.
As noted in P3358R0 ("SARIF for Structured Diagnostics"), C++
diagnostics involving concepts can be made much more readable
by capturing the hierarchical structure of the diagnostics
and displaying this structure to the user (perhaps via
a UI that allows the user to drill down into the aspects
of the issue they are interested in).
Implementing this for GCC requires several things:
(a) extending the diagnostics subsystem so that it can
represent hierarchically structured diagnostics internally
(b) extending the output formats (text and SARIF) to
present/export such hierarchical structures
(c) extending the C++ frontend to capture the hierarchical
structure
and all of these tasks are interrelated: for example,
we can't fix (c) if we don't have (a) and (b), and providing a
good user experience is likely to require iterating on all three
aspects.
Patch 1 of this patch kit implements (a) and (b), adding a plugin
to the test case to inject a placeholder hierarchical diagnostic,
adding SARIF output support (based on P3358R0), and text output support.
The most natural way to present textual output is to use indentation,
so patch 1 does this. However, our existing textual format uses the
source location as a prefix, e.g.
PATH/foo.cc: error: message goes here
and unfortunately this makes the indented hierarchy unreadable
(especially if a tree of diagnostics spans multiple source files).
So for this patch kit I've retained the existing textual presentation
by default; viewing the structure via indentation requires that
the user opt-in to a new text output style. The patch implements
this via a new "experiment-nesting" key in the text output scheme,
so the option is:
-fdiagnostics-set-output=text:experimental-nesting=yes
This is deliberately rather verbose to signal to the user that
they're opting-in to the new approach.
An example of the hierarchical text output can be seen in patch 3.
Patch 2 of the kit does some consolidation to the C++ FE in how
locations are printed, as a preliminary cleanup.
Patch 3 of the kit adds the hierarchical structuring to the C++ FE.
I've successfully bootstrapped & regrtested the kit on
x86_64-pc-linux-gnu.
I think I can self-approve patch 1; are patches 2 and 3 OK for the
C++ FE?
David Malcolm (3):
diagnostics: add support for nested diagnostics [PR116253]
c++: consolidate location printing in error.cc [PR116253]
c++: use diagnostic nesting [PR116253]
gcc/c-family/c-opts.cc | 2 +-
gcc/cp/call.cc | 69 ++++----
gcc/cp/constraint.cc | 5 +
gcc/cp/error.cc | 164 +++++++++++-------
gcc/diagnostic-core.h | 12 ++
gcc/diagnostic-format-sarif.cc | 16 +-
gcc/diagnostic-format-text.cc | 121 ++++++++++++-
gcc/diagnostic-format-text.h | 34 +++-
gcc/diagnostic-global-context.cc | 12 ++
gcc/diagnostic-show-locus.cc | 5 +
gcc/diagnostic.cc | 29 +++-
gcc/diagnostic.h | 15 +-
gcc/doc/invoke.texi | 18 ++
gcc/opts-diagnostic.cc | 32 +++-
.../concepts/nested-diagnostics-1-truncated.C | 41 +++++
.../g++.dg/concepts/nested-diagnostics-1.C | 51 ++++++
.../g++.dg/concepts/nested-diagnostics-2.C | 37 ++++
.../plugin/diagnostic-test-nesting-sarif.c | 16 ++
.../plugin/diagnostic-test-nesting-sarif.py | 39 +++++
...c-test-nesting-text-indented-show-levels.c | 24 +++
...ostic-test-nesting-text-indented-unicode.c | 24 +++
.../diagnostic-test-nesting-text-indented.c | 24 +++
.../diagnostic-test-nesting-text-plain.c | 8 +
.../plugin/diagnostic_plugin_test_nesting.c | 145 ++++++++++++++++
gcc/testsuite/gcc.dg/plugin/plugin.exp | 6 +
25 files changed, 838 insertions(+), 111 deletions(-)
create mode 100644
gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C
create mode 100644 gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C
create mode 100644 gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C
create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-sarif.c
create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-sarif.py
create mode 100644
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c
create mode 100644
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c
create mode 100644
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c
create mode 100644
gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-plain.c
create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_nesting.c
--
2.26.3