[cfe-dev] AST for C++11 brace initialization includes CompoundLiteralExpr?

Jordan Rose jordan_rose at apple.com
Fri May 3 09:46:25 PDT 2013

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130503/8f78ab6b/attachment.html>

More information about the cfe-dev mailing list