Strange type of an argument in CXXConstructExpr

Hi everyone,

Today I noticed an unusual behavior when using Clang. I found that the type of one of the arguments in a CXXConstructExpr was different from the type that I expected.

This is the fragment of code:

void QDomAttrPrivate::setNodeValue(const QString& v)
QDomTextPrivate *t = new QDomTextPrivate(0, this, v);


The invoked constructor is:
QDomTextPrivate(QDomDocumentPrivate*, QDomNodePrivate* parent, const QString& val);

and this is the related AST:

-DeclStmt 0x7f67b329cdb8 <line:4108:5, col:57>
-VarDecl 0x7f67b329c7f0 <col:5, col:56> t 'class QDomTextPrivate *' -CXXNewExpr 0x7f67b329cd60 <col:26, col:56> ‘class QDomTextPrivate *’
`-CXXConstructExpr 0x7f67b329cd18 <col:30, col:56> ‘class QDomTextPrivate’ ‘void (class QQDomDocumentPrivate *, class QDomNodePrivate *, const class QString &)’

-ImplicitCastExpr 0x7f67b329cce0 col:46 ‘class QQDomDocumentPrivate *’
-IntegerLiteral 0x7f67b329c848 <col:46> 'int' 0 -ImplicitCastExpr 0x7f67b329ccf8 <col:49> 'class QDomNodePrivate *' <DerivedToBase (QDomNodePrivate)> -CXXThisExpr 0x7f67b329c868 col:49 ‘class QDomAttrPrivate *’ this
`-DeclRefExpr 0x7f67b329c880 col:55const class QString’ lvalue ParmVar 0x7f67b329c560 ‘v’ ‘const class QString &

What I find strange is that the type of the ParmVar ‘v’ loses the ‘&’. The problem is that, when I compare the “getType()” of the third argument in the CXXConstructExpr (1) and the “getType()” of the third parameter of the constructor (2), the types do not match:

(1) const class QString
(2) const class QString &

Why is this happening? And what’s more important, how do I sort out this issue?


Expressions in C++ never have reference type. You can use getValueKind() to find if the expression is an lvalue or an rvalue. What is the problem you’re trying to solve here?

Thank you for your answer Richard. The goal is to know if there is another method (apart from the constructor) that could accept the same arguments provided in the calling. To that end, I was comparing the arguments in the calling with the parameters of other methods.

Is this the only case where the type obtained from the expression do not match with the type of the parameter? Maybe I should take the constructor declaration invoked instead of the constructor expression and compare the parameters of other methods directly with the constructor, but I can’t remember if I opted for using the construction expression for any reason.

There are lots of ways that another function could accept the same
arguments but have different parameter types. If you want to check that,
the right thing to do would be:
1) Strip off all the implicit conversions on the arguments (see
2) Try to build implicit conversion sequences from those stripped
expressions to the type of each destination parameter

Even that will not catch all cases. In particular, if you want to handle
templates, you'll need to perform template argument deduction, and if you
want to handle braced initializers as arguments, you'll need to convert
various forms of initializer back to their syntactic forms (see
TreeTransform::TransformInitializer for an idea of what's necessary there).

I have to look into all these things and find the best way to do it as general as possible. Thanks, Richard.