Ignoring system headers in a RecursiveASTVisitor

I’m building a tool with the libtooling API - running an ASTFrontendAction with a RecursiveASTVisitor.

By default, the visitor gets run for all included files, including system headers ( and the like).

I can ignore all included files (and therefore only run on the files passed on the commandline) by overriding TraversDecl and checking


Unfortunately, this stops me from traversing user included files. Ideally, I’d like to traverse non-system headers and ignore system headers. Is there a way to accomplish this?


  • Tom

I believe what you need are


The documentation has the details: http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html
Basically, you need to provide them with a SourceLocation, and they will return a boolean value. The source location you can get for example using clang::SourceManager::getLocForStartOfFile, or from any AST node.