return DirectBaseSpec || VirtualBaseSpec;
}
-/// ActOnMemInitializer - Handle a C++ member initializer.
+/// \brief Handle a C++ member initializer using braced-init-list syntax.
+MemInitResult
+Sema::ActOnMemInitializer(Decl *ConstructorD,
+ Scope *S,
+ CXXScopeSpec &SS,
+ IdentifierInfo *MemberOrBase,
+ ParsedType TemplateTypeTy,
+ SourceLocation IdLoc,
+ Expr *InitList,
+ SourceLocation EllipsisLoc) {
+ return BuildMemInitializer(ConstructorD, S, SS, MemberOrBase, TemplateTypeTy,
+ IdLoc, MultiInitializer(InitList), EllipsisLoc);
+}
+
+/// \brief Handle a C++ member initializer using parentheses syntax.
MemInitResult
Sema::ActOnMemInitializer(Decl *ConstructorD,
Scope *S,
Expr **Args, unsigned NumArgs,
SourceLocation RParenLoc,
SourceLocation EllipsisLoc) {
+ return BuildMemInitializer(ConstructorD, S, SS, MemberOrBase, TemplateTypeTy,
+ IdLoc, MultiInitializer(LParenLoc, Args, NumArgs,
+ RParenLoc),
+ EllipsisLoc);
+}
+
+/// \brief Handle a C++ member initializer.
+MemInitResult
+Sema::BuildMemInitializer(Decl *ConstructorD,
+ Scope *S,
+ CXXScopeSpec &SS,
+ IdentifierInfo *MemberOrBase,
+ ParsedType TemplateTypeTy,
+ SourceLocation IdLoc,
+ const MultiInitializer &Args,
+ SourceLocation EllipsisLoc) {
if (!ConstructorD)
return true;
= ClassDecl->lookup(MemberOrBase);
if (Result.first != Result.second) {
Member = dyn_cast<FieldDecl>(*Result.first);
-
+
if (Member) {
if (EllipsisLoc.isValid())
Diag(EllipsisLoc, diag::err_pack_expansion_member_init)
- << MemberOrBase << SourceRange(IdLoc, RParenLoc);
-
- return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
- LParenLoc, RParenLoc);
+ << MemberOrBase << SourceRange(IdLoc, Args.getEndLoc());
+
+ return BuildMemberInitializer(Member, Args, IdLoc);
}
-
+
// Handle anonymous union case.
if (IndirectFieldDecl* IndirectField
= dyn_cast<IndirectFieldDecl>(*Result.first)) {
if (EllipsisLoc.isValid())
Diag(EllipsisLoc, diag::err_pack_expansion_member_init)
- << MemberOrBase << SourceRange(IdLoc, RParenLoc);
+ << MemberOrBase << SourceRange(IdLoc, Args.getEndLoc());
- return BuildMemberInitializer(IndirectField, (Expr**)Args,
- NumArgs, IdLoc,
- LParenLoc, RParenLoc);
+ return BuildMemberInitializer(IndirectField, Args, IdLoc);
}
}
}
Diag(Member->getLocation(), diag::note_previous_decl)
<< CorrectedQuotedStr;
- return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
- LParenLoc, RParenLoc);
+ return BuildMemberInitializer(Member, Args, IdLoc);
}
} else if (TypeDecl *Type = Corr.getCorrectionDeclAs<TypeDecl>()) {
const CXXBaseSpecifier *DirectBaseSpec;
if (!TyD && BaseType.isNull()) {
Diag(IdLoc, diag::err_mem_init_not_member_or_class)
- << MemberOrBase << SourceRange(IdLoc, RParenLoc);
+ << MemberOrBase << SourceRange(IdLoc, Args.getEndLoc());
return true;
}
}
if (!TInfo)
TInfo = Context.getTrivialTypeSourceInfo(BaseType, IdLoc);
- return BuildBaseInitializer(BaseType, TInfo, (Expr **)Args, NumArgs,
- LParenLoc, RParenLoc, ClassDecl, EllipsisLoc);
+ return BuildBaseInitializer(BaseType, TInfo, Args, ClassDecl, EllipsisLoc);
}
/// Checks a member initializer expression for cases where reference (or
}
MemInitResult
-Sema::BuildMemberInitializer(ValueDecl *Member, Expr **Args,
- unsigned NumArgs, SourceLocation IdLoc,
- SourceLocation LParenLoc,
- SourceLocation RParenLoc) {
+Sema::BuildMemberInitializer(ValueDecl *Member,
+ const MultiInitializer &Args,
+ SourceLocation IdLoc) {
FieldDecl *DirectMember = dyn_cast<FieldDecl>(Member);
IndirectFieldDecl *IndirectMember = dyn_cast<IndirectFieldDecl>(Member);
assert((DirectMember || IndirectMember) &&
// foo(foo)
// where foo is not also a parameter to the constructor.
// TODO: implement -Wuninitialized and fold this into that framework.
- for (unsigned i = 0; i < NumArgs; ++i) {
+ for (MultiInitializer::iterator I = Args.begin(), E = Args.end();
+ I != E; ++I) {
SourceLocation L;
- if (InitExprContainsUninitializedFields(Args[i], Member, &L)) {
+ Expr *Arg = *I;
+ if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Arg))
+ Arg = DIE->getInit();
+ if (InitExprContainsUninitializedFields(Arg, Member, &L)) {
// FIXME: Return true in the case when other fields are used before being
// uninitialized. For example, let this field be the i'th field. When
// initializing the i'th field, throw a warning if any of the >= i'th
}
}
- bool HasDependentArg = false;
- for (unsigned i = 0; i < NumArgs; i++)
- HasDependentArg |= Args[i]->isTypeDependent();
+ bool HasDependentArg = Args.isTypeDependent();
Expr *Init;
if (Member->getType()->isDependentType() || HasDependentArg) {
// Can't check initialization for a member of dependent type or when
// any of the arguments are type-dependent expressions.
- Init = new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs,
- RParenLoc,
- Member->getType().getNonReferenceType());
+ Init = Args.CreateInitExpr(Context,Member->getType().getNonReferenceType());
DiscardCleanupsInEvaluationContext();
} else {
DirectMember ? InitializedEntity::InitializeMember(DirectMember, 0)
: InitializedEntity::InitializeMember(IndirectMember, 0);
InitializationKind Kind =
- InitializationKind::CreateDirect(IdLoc, LParenLoc, RParenLoc);
+ InitializationKind::CreateDirect(IdLoc, Args.getStartLoc(),
+ Args.getEndLoc());
- InitializationSequence InitSeq(*this, MemberEntity, Kind, Args, NumArgs);
-
- ExprResult MemberInit =
- InitSeq.Perform(*this, MemberEntity, Kind,
- MultiExprArg(*this, Args, NumArgs), 0);
+ ExprResult MemberInit = Args.PerformInit(*this, MemberEntity, Kind);
if (MemberInit.isInvalid())
return true;
- CheckImplicitConversions(MemberInit.get(), LParenLoc);
+ CheckImplicitConversions(MemberInit.get(), Args.getStartLoc());
// C++0x [class.base.init]p7:
// The initialization of each base and member constitutes a
// initializer. However, deconstructing the ASTs is a dicey process,
// and this approach is far more likely to get the corner cases right.
if (CurContext->isDependentContext()) {
- Init = new (Context) ParenListExpr(
- Context, LParenLoc, Args, NumArgs, RParenLoc,
- Member->getType().getNonReferenceType());
+ Init = Args.CreateInitExpr(Context,
+ Member->getType().getNonReferenceType());
} else {
Init = MemberInit.get();
CheckForDanglingReferenceOrPointer(*this, Member, Init, IdLoc);
if (DirectMember) {
return new (Context) CXXCtorInitializer(Context, DirectMember,
- IdLoc, LParenLoc, Init,
- RParenLoc);
+ IdLoc, Args.getStartLoc(),
+ Init, Args.getEndLoc());
} else {
return new (Context) CXXCtorInitializer(Context, IndirectMember,
- IdLoc, LParenLoc, Init,
- RParenLoc);
+ IdLoc, Args.getStartLoc(),
+ Init, Args.getEndLoc());
}
}
MemInitResult
Sema::BuildDelegatingInitializer(TypeSourceInfo *TInfo,
- Expr **Args, unsigned NumArgs,
+ const MultiInitializer &Args,
SourceLocation NameLoc,
- SourceLocation LParenLoc,
- SourceLocation RParenLoc,
CXXRecordDecl *ClassDecl) {
SourceLocation Loc = TInfo->getTypeLoc().getLocalSourceRange().getBegin();
if (!LangOpts.CPlusPlus0x)
InitializedEntity DelegationEntity = InitializedEntity::InitializeDelegation(
QualType(ClassDecl->getTypeForDecl(), 0));
InitializationKind Kind =
- InitializationKind::CreateDirect(NameLoc, LParenLoc, RParenLoc);
-
- InitializationSequence InitSeq(*this, DelegationEntity, Kind, Args, NumArgs);
+ InitializationKind::CreateDirect(NameLoc, Args.getStartLoc(),
+ Args.getEndLoc());
- ExprResult DelegationInit =
- InitSeq.Perform(*this, DelegationEntity, Kind,
- MultiExprArg(*this, Args, NumArgs), 0);
+ ExprResult DelegationInit = Args.PerformInit(*this, DelegationEntity, Kind);
if (DelegationInit.isInvalid())
return true;
= ConExpr->getConstructor();
assert(Constructor && "Delegating constructor with no target?");
- CheckImplicitConversions(DelegationInit.get(), LParenLoc);
+ CheckImplicitConversions(DelegationInit.get(), Args.getStartLoc());
// C++0x [class.base.init]p7:
// The initialization of each base and member constitutes a
return true;
assert(!CurContext->isDependentContext());
- return new (Context) CXXCtorInitializer(Context, Loc, LParenLoc, Constructor,
+ return new (Context) CXXCtorInitializer(Context, Loc, Args.getStartLoc(),
+ Constructor,
DelegationInit.takeAs<Expr>(),
- RParenLoc);
+ Args.getEndLoc());
}
MemInitResult
Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo,
- Expr **Args, unsigned NumArgs,
- SourceLocation LParenLoc, SourceLocation RParenLoc,
+ const MultiInitializer &Args,
CXXRecordDecl *ClassDecl,
SourceLocation EllipsisLoc) {
- bool HasDependentArg = false;
- for (unsigned i = 0; i < NumArgs; i++)
- HasDependentArg |= Args[i]->isTypeDependent();
+ bool HasDependentArg = Args.isTypeDependent();
SourceLocation BaseLoc
= BaseTInfo->getTypeLoc().getLocalSourceRange().getBegin();
-
+
if (!BaseType->isDependentType() && !BaseType->isRecordType())
return Diag(BaseLoc, diag::err_base_init_does_not_name_class)
<< BaseType << BaseTInfo->getTypeLoc().getLocalSourceRange();
// This is a pack expansion.
if (!BaseType->containsUnexpandedParameterPack()) {
Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
- << SourceRange(BaseLoc, RParenLoc);
-
+ << SourceRange(BaseLoc, Args.getEndLoc());
+
EllipsisLoc = SourceLocation();
}
} else {
// Check for any unexpanded parameter packs.
if (DiagnoseUnexpandedParameterPack(BaseLoc, BaseTInfo, UPPC_Initializer))
return true;
-
- for (unsigned I = 0; I != NumArgs; ++I)
- if (DiagnoseUnexpandedParameterPack(Args[I]))
- return true;
+
+ if (Args.DiagnoseUnexpandedParameterPack(*this))
+ return true;
}
-
+
// Check for direct and virtual base classes.
const CXXBaseSpecifier *DirectBaseSpec = 0;
const CXXBaseSpecifier *VirtualBaseSpec = 0;
if (!Dependent) {
if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
BaseType))
- return BuildDelegatingInitializer(BaseTInfo, Args, NumArgs, BaseLoc,
- LParenLoc, RParenLoc, ClassDecl);
+ return BuildDelegatingInitializer(BaseTInfo, Args, BaseLoc, ClassDecl);
FindBaseInitializer(*this, ClassDecl, BaseType, DirectBaseSpec,
VirtualBaseSpec);
if (Dependent) {
// Can't check initialization for a base of dependent type or when
// any of the arguments are type-dependent expressions.
- ExprResult BaseInit
- = Owned(new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs,
- RParenLoc, BaseType));
+ Expr *BaseInit = Args.CreateInitExpr(Context, BaseType);
DiscardCleanupsInEvaluationContext();
- return new (Context) CXXCtorInitializer(Context, BaseTInfo,
- /*IsVirtual=*/false,
- LParenLoc,
- BaseInit.takeAs<Expr>(),
- RParenLoc,
- EllipsisLoc);
+ return new (Context) CXXCtorInitializer(Context, BaseTInfo,
+ /*IsVirtual=*/false,
+ Args.getStartLoc(), BaseInit,
+ Args.getEndLoc(), EllipsisLoc);
}
// C++ [base.class.init]p2:
InitializedEntity BaseEntity =
InitializedEntity::InitializeBase(Context, BaseSpec, VirtualBaseSpec);
InitializationKind Kind =
- InitializationKind::CreateDirect(BaseLoc, LParenLoc, RParenLoc);
-
- InitializationSequence InitSeq(*this, BaseEntity, Kind, Args, NumArgs);
-
- ExprResult BaseInit =
- InitSeq.Perform(*this, BaseEntity, Kind,
- MultiExprArg(*this, Args, NumArgs), 0);
+ InitializationKind::CreateDirect(BaseLoc, Args.getStartLoc(),
+ Args.getEndLoc());
+
+ ExprResult BaseInit = Args.PerformInit(*this, BaseEntity, Kind);
if (BaseInit.isInvalid())
return true;
- CheckImplicitConversions(BaseInit.get(), LParenLoc);
-
+ CheckImplicitConversions(BaseInit.get(), Args.getStartLoc());
+
// C++0x [class.base.init]p7:
// The initialization of each base and member constitutes a
// full-expression.
// of the information that we have about the base
// initializer. However, deconstructing the ASTs is a dicey process,
// and this approach is far more likely to get the corner cases right.
- if (CurContext->isDependentContext()) {
- ExprResult Init
- = Owned(new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs,
- RParenLoc, BaseType));
- return new (Context) CXXCtorInitializer(Context, BaseTInfo,
- BaseSpec->isVirtual(),
- LParenLoc,
- Init.takeAs<Expr>(),
- RParenLoc,
- EllipsisLoc);
- }
+ if (CurContext->isDependentContext())
+ BaseInit = Owned(Args.CreateInitExpr(Context, BaseType));
return new (Context) CXXCtorInitializer(Context, BaseTInfo,
- BaseSpec->isVirtual(),
- LParenLoc,
- BaseInit.takeAs<Expr>(),
- RParenLoc,
- EllipsisLoc);
+ BaseSpec->isVirtual(),
+ Args.getStartLoc(),
+ BaseInit.takeAs<Expr>(),
+ Args.getEndLoc(), EllipsisLoc);
}
// Create a static_cast\<T&&>(expr).