From: Fariborz Jahanian Date: Tue, 24 Nov 2009 21:37:28 +0000 (+0000) Subject: Refactor argument collection of constructor calls using X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fe168fc8979d9640e5babec17fa5cf11400088b;p=clang 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 259bf25bed..1dda7308e0 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -3324,7 +3324,6 @@ public: unsigned FirstProtoArg, Expr **Args, unsigned NumArgs, llvm::SmallVector &AllArgs, - Expr *Fn = 0, VariadicCallType CallType = VariadicDoesNotApply); // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 58fe97a7e5..797dbf5fe2 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3645,58 +3645,22 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor, = Constructor->getType()->getAs(); 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(); - } - - 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 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 2a7758a677..45a82b5c03 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2627,7 +2627,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, else if (isa(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 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, unsigned FirstProtoArg, Expr **Args, unsigned NumArgs, llvm::SmallVector &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 4ad62f7311..40e5707028 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -411,7 +411,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, Proto->isVariadic() ? VariadicFunction : VariadicDoesNotApply; bool Invalid = GatherArgumentsForCall(PlacementLParen, OperatorNew, Proto, 1, PlaceArgs, NumPlaceArgs, - AllPlaceArgs, 0, CallType); + AllPlaceArgs, CallType); if (Invalid) return ExprError();