Determine if a variable of given type could be used as a function argument


I’m quite inexperienced with the C++ specification so apologies if this question is badly conceived.

Given a LibTooling AST I’m looking to find out if a function parameter (given by a ParmVarDecl of a FunctionDecl) would support an argument of a given QualType (the return type of another function declaration).

I know I can compare the types by == but I’m not sure how to account for implicit conversions / upcasting of the argument, and I’m having trouble finding how it’s done in the compiler. I’d rather not just construct a function call in the source code and detect errors building the AST of that, because a) I want to check parameters individually, and I’d rather not have to create a wrapper function with all but one parameters in order to create a well formed expression, and b) I want this check to conclude as fast as possible.

If you know a quick answer to how to do this with function templates also (whether a specialization can be constructed supporting one or multiple given argument types) that would be amazing, but I’m ready to do further research into that so I’d be happy for an answer ignoring templates.

All the best,


Some searching brings me to CheckSingleAssignmentConstraints, but that needs an Expr rather than a type, which I won’t always be able to get hold of.

Seems like I essentially need to adapt the internals of TryImplicitConversion and IsStandardConversion.

Will get back to this post with how that goes.