Missing CXXRecordDecl when using ClangTool

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Missing CXXRecordDecl when using ClangTool

Adam Cieszkiel via cfe-dev
Hello all,

I am using ClangTool::buildASTs to get the ASTUnit for a given file (or
to analyze them with my own RecursiveASTVisitor using the following loop.
(Here astunit is the ASTUnit returned from ClangTool::buildASTs)

for (auto decl = astuint->top_level_begin(); decl !=
astuint->top_level_end(); ++decl) {

I wonder when analysing the following code why the CXXRecordDecl for
union is
missing in the AST.

static union {
        int Member_1;
        int Member_2;

int TestObject () {
        return Member_1;

When replacing TraverseDecl(*decl); with (*decl)->dump(); I get the

VarDecl 0x378bf50
`-CXXConstructExpr 0x378c1c0
FunctionDecl 0x378c280
`-CompoundStmt 0x378c380
  `-ReturnStmt 0x378c370
    `-ImplicitCastExpr 0x378c360
      `-MemberExpr 0x378c338
        `-DeclRefExpr 0x378c320

While the output from  clang-check -ast-dump is this.

|-CXXRecordDecl 0x6000bb938
| |-FieldDecl 0x6000bba60
| |-FieldDecl 0x6000bbab8
| |-CXXConstructorDecl 0x6000bbbd0
| | `-CompoundStmt 0x6000bbf10 <col:8>
| `-CXXConstructorDecl 0x6000bbd28
|   `-ParmVarDecl 0x6000bbe70
|-VarDecl 0x6000bbb50
| `-CXXConstructExpr 0x6000bbf28
|-IndirectFieldDecl 0x600142cc0
| |-Var 0x6000bbb50
| `-Field 0x6000bba60
|-IndirectFieldDecl 0x600142d10
| |-Var 0x6000bbb50
| `-Field 0x6000bbab8
`-FunctionDecl 0x600142da0
  `-CompoundStmt 0x600142f18
    `-ReturnStmt 0x600142f00
      `-ImplicitCastExpr 0x600142ee8
        `-MemberExpr 0x600142eb0
          `-DeclRefExpr 0x600142e88

Am I missing to pass a needed option when building CommonOptionsParser
object. (CommonOptionsParser::getCompilation() ist passed when creating
the ClangTool object)

Hoping that one can help me.

cfe-dev mailing list
[hidden email]