I need to preprocess some C++ files to automatically insert code for testing and profiling, and I need to do it with the clang API.
Fo
Are there any settings to switch between C and C++ ?
Finally I found out how to handle this:
I extended from ASTConsumer
and RecursiveASTVisitor
to traverse the AST and implemented VisitCXXRecordDecl(CXXRecordDecl* D)
. Then I had to set the LangOptions
parameter for the preprocessor, so it parses C++.
langOpts.CPlusPlus = 1;
My fault was to think that it would parse C++ right away, but that was not the case, it parses C as default and so doesn't recognize classes.