Refactor argument collection of constructor calls using
the common routine.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 259bf25..1dda730 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -3324,7 +3324,6 @@
unsigned FirstProtoArg,
Expr **Args, unsigned NumArgs,
llvm::SmallVector<Expr *, 8> &AllArgs,
- Expr *Fn = 0,
VariadicCallType CallType = VariadicDoesNotApply);
// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 58fe97a..797dbf5 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -3645,58 +3645,22 @@
= Constructor->getType()->getAs<FunctionProtoType>();
assert(Proto && "Constructor without a prototype?");
unsigned NumArgsInProto = Proto->getNumArgs();
- unsigned NumArgsToCheck = NumArgs;
// If too few arguments are available, we'll fill in the rest with defaults.
- if (NumArgs < NumArgsInProto) {
- NumArgsToCheck = NumArgsInProto;
+ if (NumArgs < NumArgsInProto)
ConvertedArgs.reserve(NumArgsInProto);
- } else {
+ else
ConvertedArgs.reserve(NumArgs);
- if (NumArgs > NumArgsInProto)
- NumArgsToCheck = NumArgsInProto;
- }
-
- // Convert arguments
- for (unsigned i = 0; i != NumArgsToCheck; i++) {
- QualType ProtoArgType = Proto->getArgType(i);
-
- Expr *Arg;
- if (i < NumArgs) {
- Arg = Args[i];
-
- // Pass the argument.
- if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
- return true;
-
- Args[i] = 0;
- } else {
- ParmVarDecl *Param = Constructor->getParamDecl(i);
-
- OwningExprResult DefArg = BuildCXXDefaultArgExpr(Loc, Constructor, Param);
- if (DefArg.isInvalid())
- return true;
-
- Arg = DefArg.takeAs<Expr>();
- }
-
- ConvertedArgs.push_back(Arg);
- }
-
- // If this is a variadic call, handle args passed through "...".
- if (Proto->isVariadic()) {
- // Promote the arguments (C99 6.5.2.2p7).
- for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
- Expr *Arg = Args[i];
- if (DefaultVariadicArgumentPromotion(Arg, VariadicConstructor))
- return true;
-
- ConvertedArgs.push_back(Arg);
- Args[i] = 0;
- }
- }
-
- return false;
+
+ VariadicCallType CallType =
+ Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
+ llvm::SmallVector<Expr *, 8> AllArgs;
+ bool Invalid = GatherArgumentsForCall(Loc, Constructor,
+ Proto, 0, Args, NumArgs, AllArgs,
+ CallType);
+ for (unsigned i =0, size = AllArgs.size(); i < size; i++)
+ ConvertedArgs.push_back(AllArgs[i]);
+ return Invalid;
}
/// CompareReferenceRelationship - Compare the two types T1 and T2 to
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 2a7758a..45a82b5 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2627,7 +2627,7 @@
else if (isa<MemberExpr>(Fn))
CallType = VariadicMethod;
Invalid = GatherArgumentsForCall(Call->getSourceRange().getBegin(), FDecl,
- Proto, 0, Args, NumArgs, AllArgs, Fn, CallType);
+ Proto, 0, Args, NumArgs, AllArgs, CallType);
if (Invalid)
return true;
unsigned TotalNumArgs = AllArgs.size();
@@ -2643,7 +2643,6 @@
unsigned FirstProtoArg,
Expr **Args, unsigned NumArgs,
llvm::SmallVector<Expr *, 8> &AllArgs,
- Expr *Fn,
VariadicCallType CallType) {
unsigned NumArgsInProto = Proto->getNumArgs();
unsigned NumArgsToCheck = NumArgs;
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 4ad62f7..40e5707 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -411,7 +411,7 @@
Proto->isVariadic() ? VariadicFunction : VariadicDoesNotApply;
bool Invalid = GatherArgumentsForCall(PlacementLParen, OperatorNew,
Proto, 1, PlaceArgs, NumPlaceArgs,
- AllPlaceArgs, 0, CallType);
+ AllPlaceArgs, CallType);
if (Invalid)
return ExprError();