issue with getTypeClass when CXXRecord is declared in an include file

Hello,
With the below case I don’t have the expected type :

main file (input file of the tool) tests.h :

#include “external_lib.h” namespace Test { void fnc(const external_lib::MyClass& a); }

external_lib.h (in include path):

namespace external_lib { class MyClass { }; }

My code which returns a wrong result:

void GetSourceRange(const clang::QualType& qualType, clang::SourceRange& srcLoc) { clang::Decl* decl = nullptr; switch (qualType->getTypeClass()) { case clang::Type::Pointer: { auto pointee_type = qualType->getPointeeType(); GetSourceRange(pointee_type, srcLoc); break; } case clang::Type::Elaborated: { auto ET = qualType->getAsclang::ElaboratedType(); GetSourceRange(ET->getNamedType(), srcLoc); break; } case clang::Type::RValueReference: case clang::Type::LValueReference: { auto dref = qualType.getNonReferenceType(); GetSourceRange(dref, srcLoc); break; } case clang::Type::Record: { srcLoc = qualType->getAsclang::RecordType()->getDecl()->getSourceRange(); decl = qualType->getAsclang::RecordType()->getDecl(); break; } case clang::Type::Enum: { srcLoc = qualType->getAsclang::EnumType()->getDecl()->getSourceRange(); decl = qualType->getAsclang::EnumType()->getDecl(); break; } case clang::Type::Typedef: { srcLoc = qualType->getAsclang::TypedefType()->getDecl()->getSourceRange(); decl = qualType->getAsclang::TypedefType()->getDecl(); break; } default: { break; } } }

Firtsly the code execute the L/RVAlueReference’s case, but at the second call with type returned by getNonReferenceType() the line qualType->getTypeClass() returns clang::Type::Builtin instead of Elaborated.

What’s wrong with this case?

I haven’t the issue if MyClass is declared in main file.

Many thanks for helps.

Hello,
With the below case I don't have the expected type :

main file (input file of the tool) tests.h :

*#include "external_lib.h"* namespace Test { void fnc(const external_lib::
MyClass& a); }

*external_lib.h* (in include path):

namespace external_lib { class MyClass { }; }

My code which returns a wrong result:

void GetSourceRange(const clang::QualType& qualType, clang::SourceRange&
srcLoc) { clang::Decl* decl = nullptr; switch (qualType->getTypeClass()) {
case clang::Type::Pointer: { auto pointee_type = qualType->getPointeeType
(); GetSourceRange(pointee_type, srcLoc); break; } case clang::Type::
Elaborated: { auto ET = qualType->getAs<clang::ElaboratedType>();
GetSourceRange(ET->getNamedType(), srcLoc); break; } case clang::Type::
RValueReference: case clang::Type::LValueReference: { auto dref = qualType
.getNonReferenceType(); GetSourceRange(dref, srcLoc); break; } case clang
::Type::Record: { srcLoc = qualType->getAs<clang::RecordType>()->getDecl
()->getSourceRange(); decl = qualType->getAs<clang::RecordType>()->getDecl
(); break; } case clang::Type::Enum: { srcLoc = qualType->getAs<clang::
>()->getDecl()->getSourceRange(); decl = qualType->getAs<clang::
>()->getDecl(); break; } case clang::Type::Typedef: { srcLoc =
qualType->getAs<clang::TypedefType>()->getDecl()->getSourceRange(); decl =
qualType->getAs<clang::TypedefType>()->getDecl(); break; } default: {
break; } } }

Firtsly the code execute the L/RVAlueReference's case, but at the second
call with type returned by *getNonReferenceType*() the line
qualType->getTypeClass() returns clang::Type::Builtin instead of Elaborated.
What's wrong with this case?

I haven't the issue if MyClass is declared in main file.

My guess would be that your include paths are not configured correctly (so
that external_lib.h is not being found, or perhaps the wrong version of
that file is found), and you don't have a diagnostics renderer hooked up,
so the error message for "external_lib::MyClass" being unknown is not
printed anywhere; the BuiltinType you're seeing is probably being created
by error recovery. You can call qualType.dump() to check what type you were
given.