Unknown type name becomes int when generate AST

Hi,

I’m trying to use clang’s ParseAST() and ASTConsumer to extract all c function declarations in a source file, and then output these function declarations into another file.
It’s all good unless there is some unknown type name exists. For example,
my_type foo(int x) { // } // “my_type” is just a type identifier whose definition is missed in this translation unit.
When I use getReturnType() in RecursiveASTVisitor::VisitFunctionDecl(), it will return type “int”. So my program will output
int foo(int x);
instead of
my_type foo(int x);
I’m curious why “my_type” will be parsed as of type “int”.
When parsing this source code, clang will report an error saying “error: unknown type name ‘my_type’”. So I think clang knows it’s a type (unknown type is also a type I think).

Thanks!

Hi,

I'm trying to use clang's ParseAST() and ASTConsumer to extract all c
function declarations in a source file, and then output these function
declarations into another file.

Chances are you should have your tool fail if the code isn't successfully
parsed - otherwise the AST will be in all manner of invalid states that
you'll have to check for...