diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-05-06 16:48:12 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-05-06 16:48:12 +0000 |
commit | 2624b8157660902303bfce5551cfdd38272d01e5 (patch) | |
tree | e189d230f3951bfe2b2dbb923459722a19890959 /include/clang/Sema/Initialization.h | |
parent | b8409215523e5478b8b0aa9cdcd10038cf7651fe (diff) |
Fix representation of compound literals for C++ objects with destructors.
Previously, this compound literal expression (a GNU extension in C++):
(AggregateWithDtor){1, 2}
resulted in this AST:
`-CXXBindTemporaryExpr [...] 'struct Point' (CXXTemporary [...])
`-CompoundLiteralExpr [...] 'struct AggregateWithDtor'
`-CXXBindTemporaryExpr [...] 'struct AggregateWithDtor' (CXXTemporary [...])
`-InitListExpr [...] 'struct AggregateWithDtor'
|-IntegerLiteral [...] 'int' 1
`-IntegerLiteral [...] 'int' 2
Note the two CXXBindTemporaryExprs. The InitListExpr is really part of the
CompoundLiteralExpr, not an object in its own right. By introducing a new
entity initialization kind in Sema specifically for compound literals, we
avoid the treatment of the inner InitListExpr as a temporary.
`-CXXBindTemporaryExpr [...] 'struct Point' (CXXTemporary [...])
`-CompoundLiteralExpr [...] 'struct AggregateWithDtor'
`-InitListExpr [...] 'struct AggregateWithDtor'
|-IntegerLiteral [...] 'int' 1
`-IntegerLiteral [...] 'int' 2
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181212 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Sema/Initialization.h')
-rw-r--r-- | include/clang/Sema/Initialization.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/include/clang/Sema/Initialization.h b/include/clang/Sema/Initialization.h index 6e72ad3f4a..58781ac628 100644 --- a/include/clang/Sema/Initialization.h +++ b/include/clang/Sema/Initialization.h @@ -75,7 +75,10 @@ public: EK_ComplexElement, /// \brief The entity being initialized is the field that captures a /// variable in a lambda. - EK_LambdaCapture + EK_LambdaCapture, + /// \brief The entity being initialized is the initializer for a compound + /// literal. + EK_CompoundLiteralInit }; private: @@ -118,8 +121,8 @@ private: /// low bit indicating whether the parameter is "consumed". uintptr_t Parameter; - /// \brief When Kind == EK_Temporary, the type source information for - /// the temporary. + /// \brief When Kind == EK_Temporary or EK_CompoundLiteralInit, the type + /// source information for the temporary. TypeSourceInfo *TypeInfo; struct LN LocAndNRVO; @@ -287,7 +290,16 @@ public: SourceLocation Loc) { return InitializedEntity(Var, Field, Loc); } - + + /// \brief Create the entity for a compound literal initializer. + static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI) { + InitializedEntity Result(EK_CompoundLiteralInit, SourceLocation(), + TSI->getType()); + Result.TypeInfo = TSI; + return Result; + } + + /// \brief Determine the kind of initialization. EntityKind getKind() const { return Kind; } @@ -302,7 +314,7 @@ public: /// \brief Retrieve complete type-source information for the object being /// constructed, if known. TypeSourceInfo *getTypeSourceInfo() const { - if (Kind == EK_Temporary) + if (Kind == EK_Temporary || Kind == EK_CompoundLiteralInit) return TypeInfo; return 0; |