[cfe-dev] Expression type unexpected

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 25 10:39:02 PST 2015


On Nov 25, 2015 9:41 AM, "Daniel Dilts via cfe-dev" <cfe-dev at lists.llvm.org>
wrote:
>
> I have an AST matcher that is matching calls to a variadic function.  The
types of the expressions are really confusing me, though.
>
> The call expression that is matched is:
> log.Log<DebugLevel::error>("Some string", static_cast<const MyType>(5))
>
> The argument expression that is matched is:
> static_cast<const MyType>(5)
>
> MyType is a typedef.  Depending on what MyType is I get odd results.
>
> If MyType is int, then I get callExpr->getArg(1)->getType().getAsString()
is "MyType", and
callExpr->getArg(1)->getType().getCanonicalType().getAsString() is "int".
I will express this as "int->MyType->int".
>
> So, what I am getting is:
> int->MyType->int
> bool->int->int
> float->double->double
> char->int->int
>
> It makes sense to me that int->MyType->int occurs.  Could someone explain
what I am missing, why I get these results, and how to get what I would
expect (X->MyType->X)?

What you're seeing is the type of the argument after conversation to the
parameter type. Try

  callExpr->getArg(1)->IgnoreImplicit()->getType().getAsString()
_______________________________________________
> 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/20151125/b201789b/attachment.html>


More information about the cfe-dev mailing list