Dealing with invalid code in clang


I’m developing a code browsing tool based on clang. And one problem I have is how to handle invalid code. e.g.

#include “B.h”

class A {
B b;

if clang can’t find B.h so that B is undefined, then it seems RecursiveASTVisitor don’t even let you visit the AST for invalid “B” under FieldRecord/

However, in my use case, I really want to go to that AST node “B” and find out that it is a invalid AST and then try do to search the symbol from other places (e.g. database).

So is there anyway we could potentially access the invalid AST?