[cfe-dev] how to check if a FieldDecl is static or not?

Yafei Liu via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 20 03:20:36 PDT 2020


Hi Nathan, thanks a lot, I think your answer teaches me a way of how to
figure problems out by myself, I rarely print a class to AST for
investigation before.

On Tue, Oct 20, 2020 at 6:05 PM Nathan James <nayjames123 at gmail.com> wrote:

> Hi Yafei,
>
> Static members aren't FieldDecls, they are VarDecls.
>
> Take this example
> ---
> class Foo {
>     static int Bar;
> };
> ---
>
> AST output is (with some boilerplate removed)
> ---
> `-CXXRecordDecl class Foo definition
>   |-CXXRecordDecl implicit class Foo
>   `-VarDecl col:16 Bar 'int' static
> ---
>
> Once you have a VarDecl you should be able to use
> VarDecl::isStaticDataMember() to determine if its a static member of a
> class.
>
> ~Nathan
>
> On Tue, 2020-10-20 at 17:55 +0800, Yafei Liu via cfe-dev wrote:
> > Hi, I checked all the API in FieldDecl and didn't find how to check
> > if it is a static member, and I tried this also:
> >
> > auto FieldType = TheField->getType();
> >
> > and I cannot find any static checking in QualType either.
> >
> > So how can I check if the field is static or not?
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > https://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/20201020/eaa73123/attachment-0001.html>


More information about the cfe-dev mailing list