aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2013-05-03 15:05:50 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2013-05-03 15:05:50 +0000
commit1f78a50f8aee58f8e07f6307f4b8d0b1742e9a2b (patch)
tree2aadba4e61c99f5c7be138a78b34a6e9392ddf3f /lib/Sema/SemaInit.cpp
parent363f99d0cd6c00e54dde2bc66a3af234ed805b2c (diff)
ArrayRef'ize InitializationSequence constructor and InitializationSequence::Diagnose()
Patch by Robert Wilhelm. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181022 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp117
1 files changed, 52 insertions, 65 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 3c942fa40e..3960deaa6c 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -280,7 +280,7 @@ void InitListChecker::CheckValueInitializable(const InitializedEntity &Entity) {
SourceLocation Loc;
InitializationKind Kind = InitializationKind::CreateValue(Loc, Loc, Loc,
true);
- InitializationSequence InitSeq(SemaRef, Entity, Kind, 0, 0);
+ InitializationSequence InitSeq(SemaRef, Entity, Kind, MultiExprArg());
if (InitSeq.Failed())
hadError = true;
}
@@ -328,9 +328,9 @@ void InitListChecker::FillInValueInitForField(unsigned Init, FieldDecl *Field,
InitializationKind Kind = InitializationKind::CreateValue(Loc, Loc, Loc,
true);
- InitializationSequence InitSeq(SemaRef, MemberEntity, Kind, 0, 0);
+ InitializationSequence InitSeq(SemaRef, MemberEntity, Kind, MultiExprArg());
if (!InitSeq) {
- InitSeq.Diagnose(SemaRef, MemberEntity, Kind, 0, 0);
+ InitSeq.Diagnose(SemaRef, MemberEntity, Kind, ArrayRef<Expr *>());
hadError = true;
return;
}
@@ -446,9 +446,9 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
if (!InitExpr && !ILE->hasArrayFiller()) {
InitializationKind Kind = InitializationKind::CreateValue(Loc, Loc, Loc,
true);
- InitializationSequence InitSeq(SemaRef, ElementEntity, Kind, 0, 0);
+ InitializationSequence InitSeq(SemaRef, ElementEntity, Kind, MultiExprArg());
if (!InitSeq) {
- InitSeq.Diagnose(SemaRef, ElementEntity, Kind, 0, 0);
+ InitSeq.Diagnose(SemaRef, ElementEntity, Kind, ArrayRef<Expr *>());
hadError = true;
return;
}
@@ -809,12 +809,12 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
// FIXME: Better EqualLoc?
InitializationKind Kind =
InitializationKind::CreateCopy(expr->getLocStart(), SourceLocation());
- InitializationSequence Seq(SemaRef, Entity, Kind, &expr, 1);
+ InitializationSequence Seq(SemaRef, Entity, Kind, expr);
if (Seq) {
if (!VerifyOnly) {
ExprResult Result =
- Seq.Perform(SemaRef, Entity, Kind, MultiExprArg(&expr, 1));
+ Seq.Perform(SemaRef, Entity, Kind, expr);
if (Result.isInvalid())
hadError = true;
@@ -844,8 +844,8 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
hadError = true;
else {
ExprRes = SemaRef.DefaultFunctionArrayLvalueConversion(ExprRes.take());
- if (ExprRes.isInvalid())
- hadError = true;
+ if (ExprRes.isInvalid())
+ hadError = true;
}
UpdateStructuredListElement(StructuredList, StructuredIndex,
ExprRes.takeAs<Expr>());
@@ -2808,7 +2808,7 @@ static bool TryInitializerListConstruction(Sema &S,
static OverloadingResult
ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
- Expr **Args, unsigned NumArgs,
+ MultiExprArg Args,
OverloadCandidateSet &CandidateSet,
ArrayRef<NamedDecl *> Ctors,
OverloadCandidateSet::iterator &Best,
@@ -2834,7 +2834,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
// If we're performing copy initialization using a copy constructor, we
// suppress user-defined conversions on the arguments. We do the same for
// move constructors.
- if ((CopyInitializing || (InitListSyntax && NumArgs == 1)) &&
+ if ((CopyInitializing || (InitListSyntax && Args.size() == 1)) &&
Constructor->isCopyOrMoveConstructor())
SuppressUserConversions = true;
}
@@ -2844,8 +2844,7 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
(!OnlyListConstructors || S.isInitListConstructor(Constructor))) {
if (ConstructorTmpl)
S.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
- /*ExplicitArgs*/ 0,
- llvm::makeArrayRef(Args, NumArgs),
+ /*ExplicitArgs*/ 0, Args,
CandidateSet, SuppressUserConversions);
else {
// C++ [over.match.copy]p1:
@@ -2855,10 +2854,9 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
// context of direct-initialization, explicit conversion functions
// are also considered.
bool AllowExplicitConv = AllowExplicit && !CopyInitializing &&
- NumArgs == 1 &&
+ Args.size() == 1 &&
Constructor->isCopyOrMoveConstructor();
- S.AddOverloadCandidate(Constructor, FoundDecl,
- llvm::makeArrayRef(Args, NumArgs), CandidateSet,
+ S.AddOverloadCandidate(Constructor, FoundDecl, Args, CandidateSet,
SuppressUserConversions,
/*PartialOverloading=*/false,
/*AllowExplicit=*/AllowExplicitConv);
@@ -2878,11 +2876,10 @@ ResolveConstructorOverload(Sema &S, SourceLocation DeclLoc,
static void TryConstructorInitialization(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
- Expr **Args, unsigned NumArgs,
- QualType DestType,
+ MultiExprArg Args, QualType DestType,
InitializationSequence &Sequence,
bool InitListSyntax = false) {
- assert((!InitListSyntax || (NumArgs == 1 && isa<InitListExpr>(Args[0]))) &&
+ assert((!InitListSyntax || (Args.size() == 1 && isa<InitListExpr>(Args[0]))) &&
"InitListSyntax must come with a single initializer list argument.");
// The type we're constructing needs to be complete.
@@ -2931,15 +2928,14 @@ static void TryConstructorInitialization(Sema &S,
// If the initializer list has no elements and T has a default constructor,
// the first phase is omitted.
if (ILE->getNumInits() != 0 || !DestRecordDecl->hasDefaultConstructor())
- Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
+ Result = ResolveConstructorOverload(S, Kind.getLocation(), Args,
CandidateSet, Ctors, Best,
CopyInitialization, AllowExplicit,
/*OnlyListConstructor=*/true,
InitListSyntax);
// Time to unwrap the init list.
- Args = ILE->getInits();
- NumArgs = ILE->getNumInits();
+ Args = MultiExprArg(ILE->getInits(), ILE->getNumInits());
}
// C++11 [over.match.list]p1:
@@ -2949,7 +2945,7 @@ static void TryConstructorInitialization(Sema &S,
// elements of the initializer list.
if (Result == OR_No_Viable_Function) {
AsInitializerList = false;
- Result = ResolveConstructorOverload(S, Kind.getLocation(), Args, NumArgs,
+ Result = ResolveConstructorOverload(S, Kind.getLocation(), Args,
CandidateSet, Ctors, Best,
CopyInitialization, AllowExplicit,
/*OnlyListConstructors=*/false,
@@ -3156,8 +3152,8 @@ static void TryListInitialization(Sema &S,
return;
// - Otherwise, if T is a class type, constructors are considered.
- Expr *Arg = InitList;
- TryConstructorInitialization(S, Entity, Kind, &Arg, 1, DestType,
+ Expr *InitListAsExpr = InitList;
+ TryConstructorInitialization(S, Entity, Kind, InitListAsExpr, DestType,
Sequence, /*InitListSyntax*/true);
} else
Sequence.SetFailed(
@@ -3771,12 +3767,11 @@ static void TryValueInitialization(Sema &S,
// building the constructor call. This affects the semantics of a few
// things (such as whether an explicit default constructor can be called).
Expr *InitListAsExpr = InitList;
- Expr **Args = InitList ? &InitListAsExpr : 0;
- unsigned NumArgs = InitList ? 1 : 0;
+ MultiExprArg Args(&InitListAsExpr, InitList ? 1 : 0);
bool InitListSyntax = InitList;
- return TryConstructorInitialization(S, Entity, Kind, Args, NumArgs, T,
- Sequence, InitListSyntax);
+ return TryConstructorInitialization(S, Entity, Kind, Args, T, Sequence,
+ InitListSyntax);
}
}
@@ -3799,7 +3794,7 @@ static void TryDefaultInitialization(Sema &S,
// constructor for T is called (and the initialization is ill-formed if
// T has no accessible default constructor);
if (DestType->isRecordType() && S.getLangOpts().CPlusPlus) {
- TryConstructorInitialization(S, Entity, Kind, 0, 0, DestType, Sequence);
+ TryConstructorInitialization(S, Entity, Kind, MultiExprArg(), DestType, Sequence);
return;
}
@@ -4171,8 +4166,7 @@ static bool TryOCLZeroEventInitialization(Sema &S,
InitializationSequence::InitializationSequence(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
- Expr **Args,
- unsigned NumArgs)
+ MultiExprArg Args)
: FailedCandidateSet(Kind.getLocation()) {
ASTContext &Context = S.Context;
@@ -4180,7 +4174,7 @@ InitializationSequence::InitializationSequence(Sema &S,
// need to do this before checking whether types are dependent
// because lowering a pseudo-object expression might well give us
// something of dependent type.
- for (unsigned I = 0; I != NumArgs; ++I)
+ for (unsigned I = 0, E = Args.size(); I != E; ++I)
if (Args[I]->getType()->isNonOverloadPlaceholderType()) {
// FIXME: should we be doing this here?
ExprResult result = S.CheckPlaceholderExpr(Args[I]);
@@ -4200,7 +4194,7 @@ InitializationSequence::InitializationSequence(Sema &S,
QualType DestType = Entity.getType();
if (DestType->isDependentType() ||
- Expr::hasAnyTypeDependentArguments(llvm::makeArrayRef(Args, NumArgs))) {
+ Expr::hasAnyTypeDependentArguments(Args)) {
SequenceKind = DependentSequence;
return;
}
@@ -4210,7 +4204,7 @@ InitializationSequence::InitializationSequence(Sema &S,
QualType SourceType;
Expr *Initializer = 0;
- if (NumArgs == 1) {
+ if (Args.size() == 1) {
Initializer = Args[0];
if (!isa<InitListExpr>(Initializer))
SourceType = Initializer->getType();
@@ -4232,7 +4226,7 @@ InitializationSequence::InitializationSequence(Sema &S,
// (8.3.2), shall be initialized by an object, or function, of type T or
// by an object that can be converted into a T.
// (Therefore, multiple arguments are not permitted.)
- if (NumArgs != 1)
+ if (Args.size() != 1)
SetFailed(FK_TooManyInitsForReference);
else
TryReferenceInitialization(S, Entity, Kind, Args[0], *this);
@@ -4241,7 +4235,7 @@ InitializationSequence::InitializationSequence(Sema &S,
// - If the initializer is (), the object is value-initialized.
if (Kind.getKind() == InitializationKind::IK_Value ||
- (Kind.getKind() == InitializationKind::IK_Direct && NumArgs == 0)) {
+ (Kind.getKind() == InitializationKind::IK_Direct && Args.empty())) {
TryValueInitialization(S, Entity, Kind, *this);
return;
}
@@ -4338,7 +4332,7 @@ InitializationSequence::InitializationSequence(Sema &S,
(Kind.getKind() == InitializationKind::IK_Copy &&
(Context.hasSameUnqualifiedType(SourceType, DestType) ||
S.IsDerivedFrom(SourceType, DestType))))
- TryConstructorInitialization(S, Entity, Kind, Args, NumArgs,
+ TryConstructorInitialization(S, Entity, Kind, Args,
Entity.getType(), *this);
// - Otherwise (i.e., for the remaining copy-initialization cases),
// user-defined conversion sequences that can convert from the source
@@ -4351,11 +4345,11 @@ InitializationSequence::InitializationSequence(Sema &S,
return;
}
- if (NumArgs > 1) {
+ if (Args.size() > 1) {
SetFailed(FK_TooManyInitsForScalar);
return;
}
- assert(NumArgs == 1 && "Zero-argument case handled above");
+ assert(Args.size() == 1 && "Zero-argument case handled above");
// - Otherwise, if the source type is a (possibly cv-qualified) class
// type, conversion functions are considered.
@@ -4725,8 +4719,7 @@ static ExprResult CopyObject(Sema &S,
// Determine the arguments required to actually perform the
// constructor call (we might have derived-to-base conversions, or
// the copy constructor may have default arguments).
- if (S.CompleteConstructorCall(Constructor, MultiExprArg(&CurInitExpr, 1),
- Loc, ConstructorArgs))
+ if (S.CompleteConstructorCall(Constructor, CurInitExpr, Loc, ConstructorArgs))
return ExprError();
// Actually perform the constructor call.
@@ -4985,8 +4978,7 @@ InitializationSequence::Perform(Sema &S,
MultiExprArg Args,
QualType *ResultType) {
if (Failed()) {
- unsigned NumArgs = Args.size();
- Diagnose(S, Entity, Kind, Args.data(), NumArgs);
+ Diagnose(S, Entity, Kind, Args);
return ExprError();
}
@@ -5741,7 +5733,7 @@ static void emitBadConversionNotes(Sema &S, const InitializedEntity &entity,
bool InitializationSequence::Diagnose(Sema &S,
const InitializedEntity &Entity,
const InitializationKind &Kind,
- Expr **Args, unsigned NumArgs) {
+ ArrayRef<Expr *> Args) {
if (!Failed())
return false;
@@ -5749,7 +5741,7 @@ bool InitializationSequence::Diagnose(Sema &S,
switch (Failure) {
case FK_TooManyInitsForReference:
// FIXME: Customize for the initialized entity?
- if (NumArgs == 0) {
+ if (Args.empty()) {
// Dig out the reference subobject which is uninitialized and diagnose it.
// If this is value-initialization, this could be nested some way within
// the target type.
@@ -5761,7 +5753,7 @@ bool InitializationSequence::Diagnose(Sema &S,
(void)Diagnosed;
} else // FIXME: diagnostic below could be better!
S.Diag(Kind.getLocation(), diag::err_reference_has_multiple_inits)
- << SourceRange(Args[0]->getLocStart(), Args[NumArgs - 1]->getLocEnd());
+ << SourceRange(Args.front()->getLocStart(), Args.back()->getLocEnd());
break;
case FK_ArrayNeedsInitList:
@@ -5808,16 +5800,14 @@ bool InitializationSequence::Diagnose(Sema &S,
<< DestType << Args[0]->getType()
<< Args[0]->getSourceRange();
- FailedCandidateSet.NoteCandidates(S, OCD_ViableCandidates,
- llvm::makeArrayRef(Args, NumArgs));
+ FailedCandidateSet.NoteCandidates(S, OCD_ViableCandidates, Args);
break;
case OR_No_Viable_Function:
S.Diag(Kind.getLocation(), diag::err_typecheck_nonviable_condition)
<< Args[0]->getType() << DestType.getNonReferenceType()
<< Args[0]->getSourceRange();
- FailedCandidateSet.NoteCandidates(S, OCD_AllCandidates,
- llvm::makeArrayRef(Args, NumArgs));
+ FailedCandidateSet.NoteCandidates(S, OCD_AllCandidates, Args);
break;
case OR_Deleted: {
@@ -5910,7 +5900,7 @@ bool InitializationSequence::Diagnose(Sema &S,
R = SourceRange(InitList->getInit(0)->getLocEnd(),
InitList->getLocEnd());
else
- R = SourceRange(Args[0]->getLocEnd(), Args[NumArgs - 1]->getLocEnd());
+ R = SourceRange(Args.front()->getLocEnd(), Args.back()->getLocEnd());
R.setBegin(S.PP.getLocForEndOfToken(R.getBegin()));
if (Kind.isCStyleOrFunctionalCast())
@@ -5935,15 +5925,14 @@ bool InitializationSequence::Diagnose(Sema &S,
case FK_ListConstructorOverloadFailed:
case FK_ConstructorOverloadFailed: {
SourceRange ArgsRange;
- if (NumArgs)
- ArgsRange = SourceRange(Args[0]->getLocStart(),
- Args[NumArgs - 1]->getLocEnd());
+ if (Args.size())
+ ArgsRange = SourceRange(Args.front()->getLocStart(),
+ Args.back()->getLocEnd());
if (Failure == FK_ListConstructorOverloadFailed) {
- assert(NumArgs == 1 && "List construction from other than 1 argument.");
+ assert(Args.size() == 1 && "List construction from other than 1 argument.");
InitListExpr *InitList = cast<InitListExpr>(Args[0]);
- Args = InitList->getInits();
- NumArgs = InitList->getNumInits();
+ Args = MultiExprArg(InitList->getInits(), InitList->getNumInits());
}
// FIXME: Using "DestType" for the entity we're printing is probably
@@ -5952,8 +5941,7 @@ bool InitializationSequence::Diagnose(Sema &S,
case OR_Ambiguous:
S.Diag(Kind.getLocation(), diag::err_ovl_ambiguous_init)
<< DestType << ArgsRange;
- FailedCandidateSet.NoteCandidates(S, OCD_ViableCandidates,
- llvm::makeArrayRef(Args, NumArgs));
+ FailedCandidateSet.NoteCandidates(S, OCD_ViableCandidates, Args);
break;
case OR_No_Viable_Function:
@@ -6000,8 +5988,7 @@ bool InitializationSequence::Diagnose(Sema &S,
S.Diag(Kind.getLocation(), diag::err_ovl_no_viable_function_in_init)
<< DestType << ArgsRange;
- FailedCandidateSet.NoteCandidates(S, OCD_AllCandidates,
- llvm::makeArrayRef(Args, NumArgs));
+ FailedCandidateSet.NoteCandidates(S, OCD_AllCandidates, Args);
break;
case OR_Deleted: {
@@ -6519,7 +6506,7 @@ Sema::CanPerformCopyInitialization(const InitializedEntity &Entity,
InitializationKind Kind
= InitializationKind::CreateCopy(InitE->getLocStart(), SourceLocation());
- InitializationSequence Seq(*this, Entity, Kind, &InitE, 1);
+ InitializationSequence Seq(*this, Entity, Kind, InitE);
return !Seq.Failed();
}
@@ -6541,10 +6528,10 @@ Sema::PerformCopyInitialization(const InitializedEntity &Entity,
InitializationKind Kind = InitializationKind::CreateCopy(InitE->getLocStart(),
EqualLoc,
AllowExplicit);
- InitializationSequence Seq(*this, Entity, Kind, &InitE, 1);
+ InitializationSequence Seq(*this, Entity, Kind, InitE);
Init.release();
- ExprResult Result = Seq.Perform(*this, Entity, Kind, MultiExprArg(&InitE, 1));
+ ExprResult Result = Seq.Perform(*this, Entity, Kind, InitE);
if (!Result.isInvalid() && TopLevelOfInitList)
DiagnoseNarrowingInInitList(*this, Seq, Entity.getType(),