我正在使用 clang 和前端以及 RecursiveASTVisitor 开发 clang lib-tooling 项目。
对于以下代码(来自 llvm-clang 测试)
// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic
foo() { // expected-warning {{type specifier missing, defaults to 'int'}}
return 0;
}
y; // expected-warning {{type specifier missing, defaults to 'int'}}
Sample sam;
// rdar://6131634
void f((x)); // expected-warning {{type specifier missing, defaults to 'int'}}
// PR3702
#define PAD(ms10) { \
register i; \
}
#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
void
h19_insline(n) // expected-warning {{parameter 'n' was not declared, defaulting to type 'int'}}
{
ILPAD(); // expected-warning {{type specifier missing, defaults to 'int'}}
}
struct foo {
__extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
};
上面代码的 AST 是
如您所见,在 AST 中,变量sam被标记为无效,而变量y却不是,尽管两个变量都默认为 int。当我使用 RecursiveASTVisitor 遍历声明时,两个声明都无效。
现在的问题是如何区分这两个声明,因为 y 是隐式 int而 sam 是unresolved。
有人遇到过这样的问题吗?