Detecting implicit constructor calls


I'm trying to write a rewriter that turns implicit constructor (`A a =
4; f(4);`) calls into explicit constructor calls (`A a(4); f(A(4));`).
To find out if a constructor call is implicit, I check if the
CXXConstructExpr is wrapped in a ImplicitCastExpr. This works well,
except if the implicit conversion happens in a function parameter. In
that case, clang doesn't create an ImplicitCastExpr.

Is this intentional? If not, the attached patch fixes this. It doesn't
regress any tests, and it makes clang's ASTs more consistent.

If this is in fact intentional, what's a good way to check if a
constructor call is implicit?


ice.patch (1.23 KB)

Now that the conference is over: Ping :slight_smile:

andersca suggested on irc that I check if the SourceLocation of the
construtor call is valid to check if its an implicit call or not. I
finally got around to trying this: it doesn't work, implicit
constructors get valid SourceLocations, too.

Are there other ways to get at this information with the current AST
structure? If not, are there any comments on my patch? It makes the
AST for function parameters consistent with the AST in other places.


Explicit calls like 'A(4)' should always be CXXTemporaryObjectExprs,
not just CXXConstructExprs. Direct initializers like 'A x(4)' have
hasCXXDirectInitializer() set on the variable.

That said, I have no problem with adding the ImplicitCastExpr in this
case, although I haven't actually looked at your patch.