This strangeness looks to be cured:<br><br>code:<br><br>  A x = 3;<br>  A y = A(3);<br><br>now is parsed to:<br><br>(DeclStmt 0x32815f0 <line:10:3, col:10><br>    0x32814e0 "A x =<br>      (CXXConstructExpr 0x3281580 <col:5, col:9> 'class A''void (class A const &)' elidable<br>
        (ImplicitCastExpr 0x3281540 <col:9> 'class A' <ConstructorConversion><br>          (CXXConstructExpr 0x3282760 <col:9> 'class A''void (int)'<br>            (IntegerLiteral 0x32827b0 <col:9> 'int' 3))))"<br>
  (DeclStmt 0x3281640 <line:11:3, col:13><br>    0x3280660 "A y =<br>      (ImplicitCastExpr 0x3281d60 <col:9, col:12> 'class A' <ConstructorConversion><br>        (CXXConstructExpr 0x3281cf0 <col:9, col:12> 'class A''void (class A const &)' elidable<br>
          (ImplicitCastExpr 0x3281cb0 <col:9, col:12> 'class A const' <NoOp><br>            (CXXFunctionalCastExpr 0x3281c70 <col:9, col:12> 'class A' functional cast to class A<br>              (CXXConstructExpr 0x3281c20 <col:9, col:11> 'class A''void (int)'<br>
                (IntegerLiteral 0x3281b60 <col:11> 'int' 3))))))")<br><br><br><div class="gmail_quote">2010/2/27 Enea Zaffanella <span dir="ltr"><<a href="mailto:zaffanella@cs.unipr.it">zaffanella@cs.unipr.it</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello.<br>
<br>
I am a bit confused regarding the AST that is generated by clang++ when<br>
handling implicit/explicit calls to constructors. I would be grateful if<br>
someone would clarify a few points by going through the following examples.<br>
<br>
<br>
Let us consider the following struct definition:<br>
==============<br>
struct S {<br>
   S(int);<br>
};<br>
==============<br>
which is dumped by clang++ as follows (no surprise here):<br>
==============<br>
struct S {<br>
public:<br>
     struct S;<br>
     S(int);<br>
     inline S(struct S const &);<br>
     inline struct S &operator=(struct S const &);<br>
     inline void ~S();<br>
};<br>
=============<br>
<br>
<br>
If I construct an S object using direct initialization<br>
     S s1(1);<br>
I get the following (which is what I am expecting):<br>
=============<br>
   (DeclStmt 0x1d5eba0 <line:6:3, col:10><br>
     0x1d5ea60 "struct S s1 =<br>
       (CXXConstructExpr 0x1d5eb30 <col:5, col:8> 'struct S''void (int)'<br>
         (IntegerLiteral 0x1d5eac0 <col:8> 'int' 1))"<br>
=============<br>
<br>
<br>
If I now try with this variant<br>
      S s2 = 2;<br>
I get the following ... again, this is more or less what I was expecting:<br>
=============<br>
   (DeclStmt 0x1d5f1c0 <line:7:3, col:11><br>
     0x1d5f000 "struct S s2 =<br>
       (CXXConstructExpr 0x1d5f150 <col:5, col:10> 'struct S''void<br>
(struct S const &)' elidable<br>
         (ImplicitCastExpr 0x1d5f110 <col:10> 'struct S'<br>
<ConstructorConversion><br>
           (CXXConstructExpr 0x1d5f0a0 <col:10> 'struct S''void (int)'<br>
             (IntegerLiteral 0x1d5f060 <col:10> 'int' 2))))"<br>
=============<br>
I guess that the implicit cast between the two constructor calls is<br>
meant to convert the plain S type into a "const S&" type, so that it can<br>
be passed as an argument to the (elidable) copy constructor.<br>
Am I correct?<br>
<br>
<br>
But then I get to the following case<br>
     S s3 = S(3);<br>
for which I get the following AST:<br>
=============<br>
   (DeclStmt 0x1d5f430 <line:8:3, col:14><br>
     0x1d5f1f0 "struct S s3 =<br>
       (ImplicitCastExpr 0x1d5f3f0 <col:10, col:13> 'struct S'<br>
<ConstructorConversion><br>
         (CXXConstructExpr 0x1d5f380 <col:10, col:13> 'struct S''void<br>
(struct S const &)' elidable<br>
           (ImplicitCastExpr 0x1d5f340 <col:10, col:13> 'struct S const'<br>
<NoOp><br>
             (CXXFunctionalCastExpr 0x1d5f300 <col:10, col:13> 'struct<br>
S' functional cast to struct S<br>
               (CXXConstructExpr 0x1d5f290 <col:10, col:12> 'struct<br>
S''void (int)'<br>
                 (IntegerLiteral 0x1d5f250 <col:12> 'int' 3))))))"<br>
=============<br>
<br>
Here there are two things that I do not understand.<br>
<br>
First, I cannot see why the result of the inner CXXConstructorExpr call<br>
should be fed to a CXXFunctionalCastExpr. I may agree that the<br>
initializer of s3 is a functional cast expression ... but then I would<br>
expect that the argument of this functional cast is the integer literal,<br>
not the struct S object returned by the constructor.<br>
In other words, to my eyes, the presence of the functional cast should<br>
exclude the presence of the inner constructor call, or vice versa.<br>
Is my reasoning missing some important point?<br>
<br>
Second, I cannot see why the result of the external (elidable) copy<br>
constructor call is (again) implicitly cast before being used as an<br>
initializer for s3. There seems to be no reason for such an implicit<br>
cast and, as a matter of fact, such a cast was not used in the previous<br>
example (when initializing s2).<br>
<br>
I would be grateful if someone either confirm my doubts or show to me<br>
where is the gap in my reasoning.<br>
<br>
Regards,<br>
Enea Zaffanella.<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br>