[cfe-dev] Strange type of an argument in CXXConstructExpr

victor via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 10 00:37:25 PST 2015


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

Date: Mon, 9 Nov 2015 16:37:11 -0800
Subject: Re: [cfe-dev] Strange type of an argument in CXXConstructExpr
From: richard at metafoo.co.uk
To: pedretti_86 at hotmail.com
CC: cfe-dev at lists.llvm.org

On Mon, Nov 9, 2015 at 4:41 AM, victor <pedretti_86 at hotmail.com> wrote:



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 Expr::IgnoreImplicit)2) Try to build implicit conversion sequences from those stripped expressions to the type of each destination parameter (Sema::TryImplicitConversion)
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).
Date: Sun, 8 Nov 2015 12:24:09 -0800
Subject: Re: [cfe-dev] Strange type of an argument in CXXConstructExpr
From: richard at metafoo.co.uk
To: pedretti_86 at hotmail.com
CC: cfe-dev at lists.llvm.org

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?
On Nov 8, 2015 6:30 AM, "victor via cfe-dev" <cfe-dev at lists.llvm.org> wrote:



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 *' <NullToPointer>
|   |       | `-IntegerLiteral 0x7f67b329c848 <col:46> 'int' 0
|   |       |-ImplicitCastExpr 0x7f67b329ccf8 <col:49> 'class QDomNodePrivate *' <DerivedToBase (QDomNodePrivate)>
|   |       | `-CXXThisExpr 0x7f67b329c868 <col:49> 'class QDomAttrPrivate *' this
|   |       `-DeclRefExpr 0x7f67b329c880 <col:55> 'const 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? 

Thanks. 		 	   		  

_______________________________________________

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/20151110/ee6d0b08/attachment.html>


More information about the cfe-dev mailing list