我正在尝试使用 libtooling 构建工具。使用 clang 转储 AST 时,我发现 Foo 类报告了两个 CXXRecordDecl。似乎外部 CXXRecordDecl 有一个 CXXRecordDecl 子级,它说它是隐式类 Foo。这是为什么?
2 回答
0
它只是一个类声明。
在您的示例中,您会注意到这两个CXXRecordDecl的位置不同,嵌套的位置对应于Foo的前向声明。如果没有前向声明,定义将指向自身。
于 2019-06-08T23:27:52.693 回答
0
至少知道如何匹配一个是有用的:
// test.cpp
class Foo {};
int main() { return 0; }
使用 ast 匹配器
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.
它不是前向声明,可能是编译后定义的隐式构造函数。
于 2020-04-17T10:50:41.700 回答