[cfe-dev] issue with getTypeClass when CXXRecord is declared in an include file

ogzu rasa via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 2 05:58:29 PDT 2018


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::EnumType>()->getDecl()->
getSourceRange(); decl = qualType->getAs<clang::EnumType>()->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.


Many thanks for helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180402/2f950bbf/attachment.html>


More information about the cfe-dev mailing list