diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 62a41f5b78..7152f04b88 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1757,11 +1757,12 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, SourceLocation()); OwningExprResult Res = PerformCopyInitialization( - InitializedEntity::InitializeResult(SourceLocation(), - T, false), + InitializedEntity::InitializeBlock(VD->getLocation(), + T, false), SourceLocation(), Owned(E)); if (!Res.isInvalid()) { + Res = MaybeCreateCXXExprWithTemporaries(move(Res)); Expr *Init = Res.takeAs(); if (isa(Init)) BDRE->setCopyConstructorExpr(Init); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index e34e1683e8..ac073604ee 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -1956,6 +1956,7 @@ DeclarationName InitializedEntity::getName() const { case EK_Base: case EK_ArrayElement: case EK_VectorElement: + case EK_BlockElement: return DeclarationName(); } @@ -1977,6 +1978,7 @@ DeclaratorDecl *InitializedEntity::getDecl() const { case EK_Base: case EK_ArrayElement: case EK_VectorElement: + case EK_BlockElement: return 0; } @@ -1998,6 +2000,7 @@ bool InitializedEntity::allowsNRVO() const { case EK_Base: case EK_ArrayElement: case EK_VectorElement: + case EK_BlockElement: break; } @@ -3170,6 +3173,7 @@ getAssignmentAction(const InitializedEntity &Entity) { case InitializedEntity::EK_Member: case InitializedEntity::EK_ArrayElement: case InitializedEntity::EK_VectorElement: + case InitializedEntity::EK_BlockElement: return Sema::AA_Initializing; } @@ -3188,6 +3192,7 @@ static bool shouldBindAsTemporary(const InitializedEntity &Entity) { case InitializedEntity::EK_Base: case InitializedEntity::EK_VectorElement: case InitializedEntity::EK_Exception: + case InitializedEntity::EK_BlockElement: return false; case InitializedEntity::EK_Parameter: @@ -3207,6 +3212,7 @@ static bool shouldDestroyTemporary(const InitializedEntity &Entity) { case InitializedEntity::EK_New: case InitializedEntity::EK_Base: case InitializedEntity::EK_VectorElement: + case InitializedEntity::EK_BlockElement: return false; case InitializedEntity::EK_Variable: @@ -3291,6 +3297,7 @@ static Sema::OwningExprResult CopyObject(Sema &S, case InitializedEntity::EK_New: case InitializedEntity::EK_Base: case InitializedEntity::EK_VectorElement: + case InitializedEntity::EK_BlockElement: Loc = CurInitExpr->getLocStart(); break; } diff --git a/lib/Sema/SemaInit.h b/lib/Sema/SemaInit.h index a9064ede6d..44c36a735b 100644 --- a/lib/Sema/SemaInit.h +++ b/lib/Sema/SemaInit.h @@ -66,7 +66,10 @@ public: EK_Base, /// \brief The entity being initialized is an element of a vector. /// or vector. - EK_VectorElement + EK_VectorElement, + /// \brief The entity being initialized is a field of block descriptor for + /// the copied-in c++ object. + EK_BlockElement }; private: @@ -166,6 +169,11 @@ public: return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO); } + static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, + QualType Type, bool NRVO) { + return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO); + } + /// \brief Create the initialization entity for an exception object. static InitializedEntity InitializeException(SourceLocation ThrowLoc, QualType Type, bool NRVO) {