Missing info in AST for CXXConstructExpr

Richard Smith richard at metafoo.co.uk
Mon Jan 26 17:50:24 PST 2015


On Sat, Jan 24, 2015 at 3:40 AM, Abramo Bagnara <abramo.bagnara at bugseng.com>
wrote:
>
> For the following source:
>
> #include <initializer_list>
> typedef std::initializer_list<int> T;
>
> void f(T);
>
> template <typename U>
> void g(U);
>
> int main() {
>   f(T{0});
>   g(T{0});
> }
>
> I get this AST (initial part is omitted as it is not relevant):
>
> `-FunctionDecl 0x7960cc0 <line:9:1, line:12:1> line:9:5 main 'int (void)'
>   `-CompoundStmt 0x7962d50 <col:12, line:12:1>
>     |-CallExpr 0x7962180 <line:10:3, col:9> 'void'
>     | |-ImplicitCastExpr 0x7962168 <col:3> 'void (*)(T)'
> <FunctionToPointerDecay>
>     | | `-DeclRefExpr 0x79620e0 <col:3> 'void (T)' lvalue Function
> 0x7960940 'f' 'void (T)'
>     | `-CXXConstructExpr 0x79627a8 <col:6, col:8> 'T':'class
> std::initializer_list<int>' 'void (class std::initializer_list<int> &&)
> noexcept' elidable
>     |   `-MaterializeTemporaryExpr 0x7962550 <col:6, col:8> 'class
> std::initializer_list<int>' xvalue
>     |     `-CXXStdInitializerListExpr 0x7961fa8 <col:6, col:8>
> 'T':'class std::initializer_list<int>'
>     |       `-MaterializeTemporaryExpr 0x7961f90 <col:6, col:8> 'const
> int [1]' xvalue
>     |         `-InitListExpr 0x7961f48 <col:6, col:8> 'const int [1]'
>     |           `-IntegerLiteral 0x7960e20 <col:7> 'int' 0
>     `-CallExpr 0x7962cd0 <line:11:3, col:9> 'void'
>       |-ImplicitCastExpr 0x7962cb8 <col:3> 'void (*)(class
> std::initializer_list<int>)' <FunctionToPointerDecay>
>       | `-DeclRefExpr 0x7962c60 <col:3> 'void (class
> std::initializer_list<int>)' lvalue Function 0x7962b60 'g' 'void (class
> std::initializer_list<int>)' (FunctionTemplate 0x7960c20 'g')
>       `-CXXConstructExpr 0x7962d18 <col:6, col:8> 'class
> std::initializer_list<int>':'class std::initializer_list<int>' 'void
> (class std::initializer_list<int> &&) noexcept' elidable
>         `-MaterializeTemporaryExpr 0x7962d00 <col:6, col:8> 'class
> std::initializer_list<int>' xvalue
>           `-CXXStdInitializerListExpr 0x7962910 <col:6, col:8>
> 'T':'class std::initializer_list<int>'
>             `-MaterializeTemporaryExpr 0x79628f8 <col:6, col:8> 'const
> int [1]' xvalue
>               `-InitListExpr 0x79628b0 <col:6, col:8> 'const int [1]'
>                 `-IntegerLiteral 0x7962848 <col:7> 'int' 0
>
> Looking at AST (and clang sources) I can note two things:
>
> 1) no nodes contains the written TypeLoc for T in function calls
> 2) the source range for CXXConstructExpr is wrong
> 3) the type is not printed by StmtPrinter.
>
> Once confirmed that, what is the node that should contain such type info
> (if any)?

There should be a CXXFunctionalCastExpr (with cast kind CK_NoOp) between
the MaterializeTemporaryExpr and its contained CXXStdInitializerListExpr:

    `-CallExpr 0x7962cd0 <line:11:3, col:9> 'void'
      |-ImplicitCastExpr 0x7962cb8 <col:3> 'void
(*)(class std::initializer_list<int>)' <FunctionToPointerDecay>
      | `-DeclRefExpr 0x7962c60 <col:3> 'void
(class std::initializer_list<int>)' lvalue [...]
      `-CXXConstructExpr 0x7962d18 <col:6, col:8> [...]
        `-MaterializeTemporaryExpr 0x7962d00 <col:6, col:8>
'class std::initializer_list<int>' xvalue

*          `-CXXFunctionalCastExpr 0x... <NoOp>*
`-CXXStdInitializerListExpr 0x7962910 <col:6, col:8> 'T':'class
std::initializer_list<int>'
              `-MaterializeTemporaryExpr 0x79628f8 <col:6, col:8>
'const int [1]' xvalue
                `-InitListExpr 0x79628b0 <col:6, col:8> 'const int [1]'
                  `-IntegerLiteral 0x7962848 <col:7> 'int' 0

This case appears to be missing from Sema::BuildCXXTypeConstructExpr; it
looks like it assumes that initialization will give us either a
CXXConstructExpr or an InitListExpr.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150126/bd987b5d/attachment.html>


More information about the cfe-commits mailing list