I'm trying to build tools with libtooling. when using clang to dump AST, i found that two CXXRecordDecl were reported for class Foo. It seems that the outer CXXRecordDecl has a CXXRecordDecl child which says it's implicit class Foo. Why is that?
Asked
Active
Viewed 378 times
2 Answers
0
It is simply a class declaration.
In your example, you can notice that these two CXXRecordDecl's have different locations and the nested one corresponds to Foo's forward declaration. Without a forward declaration, definition will be pointing at itself.

Valeriy Savchenko
- 1,524
- 8
- 19
0
At lease it's useful to know how to match one over the other:
// test.cpp
class Foo {};
int main() { return 0; }
using ast matcher
clang-query> m cxxRecordDecl(hasName("Foo"))
Match #1:
test.cpp:2:1: note: "root" binds here
class Foo {
^~~~~~~~~~~
Match #2:
test.cpp:2:1: note: "root" binds here
class Foo {
^~~~~~~~~
2 matches.
clang-query> m cxxRecordDecl(hasName("Foo"),unless(isImplicit()))
Match #1:
test.cpp:2:1: note: "root" binds here
class Foo {
^~~~~~~~~~~
1 match.
It's not a forward declaration, probably a compiled defined implicit constructor.

Booo
- 493
- 3
- 13