[cfe-dev] API to check if a decl is a pointer

Himanshu via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 25 09:36:52 PDT 2016


For anyone else who might want to do this, I believe the API has changed
slightly. I think as per the new API, one needs to do:

*bool* isPtr = VD->getType().*getTypePtr*()->*isPointerType*();

--
Himanshu

On Mon, Jul 25, 2016 at 9:03 AM, Aaron Ballman <aaron at aaronballman.com>
wrote:

> On Mon, Jul 25, 2016 at 12:00 PM, Himanshu via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
> > Hi All,
> >
> > Is there an API that allows one to check if a DeclRefExpr or its
> > corresponding VarDecl is of a pointer type? For example:
> >
> > int *pI;  // yes -- a pointer type
> > int i; // no.
> >
> > I could use a string based check -- getting the type name as string and
> then
> > searching for '*' in it, but I believe there must be a cleaner and robust
> > way to do so.
>
> You can call getType() on the VarDecl (because it inherits from
> ValueDecl), and then check isPointerType() on the resulting QualType
> object (it wraps a Type *). e.g.,
>
> QualType QT = YourVarDecl->getType();
> if (QT->isPointerType()) {
>
> }
>
> ~Aaron
>
> >
> > Thanks!
> >
> > _______________________________________________
> > 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/20160725/fddc5d21/attachment.html>


More information about the cfe-dev mailing list