Hi Clang Developers,
I've previously posted on this mailing list about trouble I was having
parsing files with syntax errors using the method used in
IncrementalProcessingTest.cpp. My earlier email is here:
TLDR: At the moment, the way that the incremental processing unit test
shows C++ code being parsed will segfault if the code has any syntax
I've now figured out how to resolve this issue. The trick is to enter
the source file with the compilers diagnostics client before the
buffer is parse on line 78 and 94.
CI.getLangOpts(), &CI.getPreprocessor() );
// ... parse the file
Doing this will cause diagnostics to be printed as expected. I think
that it would be appropriate to add this to unit tests that currently
use clang::ParseAST as it might be useful to other people who refers
to those for code examples.
If that sounds appropriate to you all, then I can go ahead and submit
a patch. Otherwise I'd appreciate some input on where it might be
appropriate to add documentation on this as it seems fairly confusing.
I've pasted a diff of a sketch of the changes I'm proposing below.
< clang::DiagnosticConsumer& DC = CI.getDiagnosticClient();
< DC.clear(); // Clear out any pre existing errors.
< DC.BeginSourceFile( CI.getLangOpts(), &CI.getPreprocessor() );
< if ( DC.getNumErrors() ) // An error occured parsing the file.
< return nullptr;