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

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 25 09:03:19 PDT 2016


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
>



More information about the cfe-dev mailing list