[cfe-dev] How to determine if Decl is a RecordDecl?

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 11 07:24:19 PST 2020


On Wed, Nov 11, 2020 at 10:21 AM Marcel Schaible via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> I am currently devoloping a tool, which collects Decl with a
> user-defined attribute.
>
> At the moement I am storing these Decls in a vector.
>
> Afterwards I want to iterate over the vector of Decls and want to
> determine if a element is e.g. of type RecordDecl or CxxRecordDecl
>
> What is the preferred way for achieving this?

You can use isa<CXXRecordDecl>(TheDecl) to test what kind of
declaration it is, or dyn_cast<RecordDecl>(TheDecl) or
cast<RecordDecl>(TheDecl) to convert the declaration to the more
derived type. See
https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates
for more details.

HTH!

~Aaron

>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list