I'm playing with libclang and I ran into a weird problem.
I wrote a small parser with libclang and in my visitor passed to clang_parseTranslationUnit I have:
CXChildVisitResult visitor(CXCursor cursor, CXCursor, CXClientData)
{
const auto cursorKind = clang_getCursorKind(cursor);
if (cursorKind == CXCursor_FieldDecl)
{
const CXType cxtype = clang_getCursorType(cursor);
std::cout << clang_getCString(clang_getTypeSpelling(cxtype)) << \n";
}
return CXChildVisit_Continue;
}
It works almost fine. If I parse a file:
#include <vector>
class AAA
{
public:
std::vector<int> a;
float b;
};
it prints int when visiting a member which is of type std::vector<int>.
I've check for many various template containers from std and it behaves like that for all of them. From the other side there is no problem if I, for example, use containers from Qt like QList<int>.
What can be wrong here? I use libclang 16.0.6 on linux.
You need to give your parser the include path to the standard library, which it needs to find the header file for
vector.