clang errors vs clang_getDiagnostics


I have a problem with using diagnostics with the C API.

I do this on the command line:


void foobar();

int main() {

clang main.cpp

I get this:

main.cpp:4:3: error: use of undeclared identifier 'foobaz'; did you
mean 'foobar'?
main.cpp:1:6: note: 'foobar' declared here
void foobar();
1 error generated.

If I do the same thing with clang_parseTranslationUnit and then
clang_getDiagnostic I don't seem to get this suggestion. I just get:

error: use of undeclared identifier 'foobaz' [2, Semantic Issue]

Do I need to pass a switch that is on by default for clang itself?



Oops. I found it. -fspell-checking. Sorry for the spam.


I think it's Clang (not libclang) that outputs the error message in this format. What you get from libclang is only a simple default implementation of formatting error messages.

Oops. I found it. -fspell-checking. Sorry for the spam.

Right. We did this because spell-checking/typo correction can have a significant impact on performance, so we turned it off by default for libclang clients, which are likely to care more about performance.

  - Doug

Cool. Thanks.