diff options
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 104 |
1 files changed, 19 insertions, 85 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index fd33b3164b0..ba62be2f5ff 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -4246,98 +4246,30 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, CtorArg = CastForMoving(SemaRef, CtorArg.get()); } - // When the field we are copying is an array, create index variables for - // each dimension of the array. We use these index variables to subscript - // the source array, and other clients (e.g., CodeGen) will perform the - // necessary iteration with these index variables. - SmallVector<VarDecl *, 4> IndexVariables; - QualType BaseType = Field->getType(); - QualType SizeType = SemaRef.Context.getSizeType(); - bool InitializingArray = false; - while (const ConstantArrayType *Array - = SemaRef.Context.getAsConstantArrayType(BaseType)) { - InitializingArray = true; - // Create the iteration variable for this array index. - IdentifierInfo *IterationVarName = nullptr; - { - SmallString<8> Str; - llvm::raw_svector_ostream OS(Str); - OS << "__i" << IndexVariables.size(); - IterationVarName = &SemaRef.Context.Idents.get(OS.str()); - } - VarDecl *IterationVar - = VarDecl::Create(SemaRef.Context, SemaRef.CurContext, Loc, Loc, - IterationVarName, SizeType, - SemaRef.Context.getTrivialTypeSourceInfo(SizeType, Loc), - SC_None); - IndexVariables.push_back(IterationVar); - - // Create a reference to the iteration variable. - ExprResult IterationVarRef - = SemaRef.BuildDeclRefExpr(IterationVar, SizeType, VK_LValue, Loc); - assert(!IterationVarRef.isInvalid() && - "Reference to invented variable cannot fail!"); - IterationVarRef = SemaRef.DefaultLvalueConversion(IterationVarRef.get()); - assert(!IterationVarRef.isInvalid() && - "Conversion of invented variable cannot fail!"); - - // Subscript the array with this iteration variable. - CtorArg = SemaRef.CreateBuiltinArraySubscriptExpr(CtorArg.get(), Loc, - IterationVarRef.get(), - Loc); - if (CtorArg.isInvalid()) - return true; - - BaseType = Array->getElementType(); - } - - // The array subscript expression is an lvalue, which is wrong for moving. - if (Moving && InitializingArray) - CtorArg = CastForMoving(SemaRef, CtorArg.get()); + InitializedEntity Entity = + Indirect ? InitializedEntity::InitializeMember(Indirect, nullptr, + /*Implicit*/ true) + : InitializedEntity::InitializeMember(Field, nullptr, + /*Implicit*/ true); - // Construct the entity that we will be initializing. For an array, this - // will be first element in the array, which may require several levels - // of array-subscript entities. - SmallVector<InitializedEntity, 4> Entities; - Entities.reserve(1 + IndexVariables.size()); - if (Indirect) - Entities.push_back(InitializedEntity::InitializeMember(Indirect)); - else - Entities.push_back(InitializedEntity::InitializeMember(Field)); - for (unsigned I = 0, N = IndexVariables.size(); I != N; ++I) - Entities.push_back(InitializedEntity::InitializeElement(SemaRef.Context, - 0, - Entities.back())); - // Direct-initialize to use the copy constructor. InitializationKind InitKind = InitializationKind::CreateDirect(Loc, SourceLocation(), SourceLocation()); Expr *CtorArgE = CtorArg.getAs<Expr>(); - InitializationSequence InitSeq(SemaRef, Entities.back(), InitKind, - CtorArgE); - - ExprResult MemberInit - = InitSeq.Perform(SemaRef, Entities.back(), InitKind, - MultiExprArg(&CtorArgE, 1)); + InitializationSequence InitSeq(SemaRef, Entity, InitKind, CtorArgE); + ExprResult MemberInit = + InitSeq.Perform(SemaRef, Entity, InitKind, MultiExprArg(&CtorArgE, 1)); MemberInit = SemaRef.MaybeCreateExprWithCleanups(MemberInit); if (MemberInit.isInvalid()) return true; - if (Indirect) { - assert(IndexVariables.size() == 0 && - "Indirect field improperly initialized"); - CXXMemberInit - = new (SemaRef.Context) CXXCtorInitializer(SemaRef.Context, Indirect, - Loc, Loc, - MemberInit.getAs<Expr>(), - Loc); - } else - CXXMemberInit = CXXCtorInitializer::Create(SemaRef.Context, Field, Loc, - Loc, MemberInit.getAs<Expr>(), - Loc, - IndexVariables.data(), - IndexVariables.size()); + if (Indirect) + CXXMemberInit = new (SemaRef.Context) CXXCtorInitializer( + SemaRef.Context, Indirect, Loc, Loc, MemberInit.getAs<Expr>(), Loc); + else + CXXMemberInit = new (SemaRef.Context) CXXCtorInitializer( + SemaRef.Context, Field, Loc, Loc, MemberInit.getAs<Expr>(), Loc); return false; } @@ -4348,9 +4280,11 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, SemaRef.Context.getBaseElementType(Field->getType()); if (FieldBaseElementType->isRecordType()) { - InitializedEntity InitEntity - = Indirect? InitializedEntity::InitializeMember(Indirect) - : InitializedEntity::InitializeMember(Field); + InitializedEntity InitEntity = + Indirect ? InitializedEntity::InitializeMember(Indirect, nullptr, + /*Implicit*/ true) + : InitializedEntity::InitializeMember(Field, nullptr, + /*Implicit*/ true); InitializationKind InitKind = InitializationKind::CreateDefault(Loc); |