[cfe-dev] Diagnostic Improvements

Doug Gregor doug.gregor at gmail.com
Mon Nov 17 07:31:19 PST 2008


On Mon, Nov 17, 2008 at 12:25 AM, Chris Lattner <clattner at apple.com> wrote:
> I've been pondering on diagnostics a bit lately, and reviewing one of
> Doug's patches got me to thinking about this more intently.  Here are
> three problems I've noticed with Clang's current diagnostics:
[snip]
> I think it is time to stop the madness.  Currently, diagnostics are
> passed down into DiagnosticClient with an array of strings that are
> referenced by substitutions, and turned into the final string by
> DiagnosticClient::FormatDiagnostic.  I think it would be straight-
> forward to change this to be an array of void*, where (at the
> beginning) all of these are pointers to std::string.  Once that was
> done, we can start introducing some more rich formatting characters
> like "%T0" instead of "%0" and making the corresponding pointers be to
> richer thing than strings.  For example, "%T0" format the 0th element
> of the array as a QualType.  We could also introduce things like %u0
> (unsigned int) and %i0 (signed int).
[snip]
> Does this seem like a reasonable thing to do?

GCC does something very similar to this, and it works quite well. They
have printf-like specifiers such as '%T' (print a type node), '%E'
(print an expression node), with qualifiers like 'q' (qualified name,
e.g., '%qT' prints 'foo::bar::MyClass' instead of just 'MyClass') to
tweak the output. We definitely need something like this for Clang,
and as long as the result is type-safe (e.g., asserts if you write
'%T0' and give it a string), I'm fine with whatever markup we choose.

This would also be a great time to make Clang's error output word wrap
when written to a terminal...

  - Doug



More information about the cfe-dev mailing list