Expression type unexpected

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.LogDebugLevel::error(“Some string”, static_cast(5))

The argument expression that is matched is:
static_cast(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)?

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)?

I am seeing in the AST an ImplicitCastExpr to int. Why is this present? I thought that the arguments are passed to a variadic function as their actual types.

The default argument promotions (and some others, such as nullptr_t ->
void*) apply per [expr.call]p7 (in C++11).

-- James

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

callExpr->getArg(1)->IgnoreImplicit()->getType().getAsString()