[cfe-dev] AST for C++11 brace initialization includes CompoundLiteralExpr?
Jordan Rose
jordan_rose at apple.com
Fri May 3 11:01:38 PDT 2013
On May 3, 2013, at 10:02 , Douglas Gregor <dgregor at apple.com> wrote:
>
> On May 3, 2013, at 9:46 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>
>> Hi, Richard, Doug, et al. Somebody internally came up with a C++11 example that generates a strange AST:
>>
>>> struct Point {
>>> Point(int x, int y);
>>> };
>>>
>>> void use(Point);
>>>
>>> void test() {
>>> use((Point){1, 2});
>>> }
>>
>> `-FunctionDecl 0x7fa6410604b0 <line:7:1, line:9:1> test 'void (void)'
>> `-CompoundStmt 0x7fa641060d00 <line:7:13, line:9:1>
>> `-CallExpr 0x7fa641060c30 <line:8:2, col:19> 'void'
>> |-ImplicitCastExpr 0x7fa641060c18 <col:2> 'void (*)(struct Point)' <FunctionToPointerDecay>
>> | `-DeclRefExpr 0x7fa641060bc8 <col:2> 'void (struct Point)' lvalue Function 0x7fa6410603b0 'use' 'void (struct Point)'
>> `-CXXConstructExpr 0x7fa641060cc8 <col:6> 'struct Point' 'void (struct Point &&) noexcept' elidable
>> `-MaterializeTemporaryExpr 0x7fa641060c60 <col:6, <invalid sloc>> 'struct Point' xvalue
>> `-CompoundLiteralExpr 0x7fa641060ba0 <col:6, <invalid sloc>> 'struct Point'
>> `-CXXTemporaryObjectExpr 0x7fa641060a00 <col:6, <invalid sloc>> 'struct Point' 'void (int, int)'
>> |-IntegerLiteral 0x7fa6410605b8 <col:14> 'int' 1
>> `-IntegerLiteral 0x7fa6410605d8 <col:17> 'int' 2
>>
>> Notice the CXXTemporaryObjectExpr inside the CompoundLiteralExpr. Normally a CompoundLiteralExpr is used to initialize aggregates, and so its child is an InitListExpr. Here, though, the object is being initialized via a constructor, and so it's not really a compound literal at all, even though it looks like one. I can hack around this in the analyzer, but honestly I don't think we be forming a CompoundLiteralExpr at all. What do you think?
>
> It actually is a compound literal, because this isn't syntax that would be accepted by pure C++11. So, it should be described as a CompoundLiteralExpr in the AST. We could clean up the AST for CompoundLiteralExpr to directly describe constructor calls, but this representation doesn't seem wrong per se.
Well, that's weird. Okay, thanks for the explanation.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130503/55f642af/attachment.html>
More information about the cfe-dev
mailing list