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

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 2 11:04:32 PDT 2018


On 2 April 2018 at 05:58, ogzu rasa via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> 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.
>

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.


> Many thanks for helps.
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180402/d74d1793/attachment.html>


More information about the cfe-dev mailing list