diff options
-rw-r--r-- | include/clang/AST/ExprCXX.h | 10 | ||||
-rw-r--r-- | lib/AST/ExprCXX.cpp | 21 |
2 files changed, 24 insertions, 7 deletions
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 791d94ded0..b10191002f 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -517,6 +517,16 @@ public: unsigned getNumArgs() const { return NumArgs; } + /// getArg - Return the specified argument. + Expr *getArg(unsigned Arg) { + assert(Arg < NumArgs && "Arg access out of range!"); + return cast<Expr>(Args[Arg]); + } + const Expr *getArg(unsigned Arg) const { + assert(Arg < NumArgs && "Arg access out of range!"); + return cast<Expr>(Args[Arg]); + } + /// setArg - Set the specified argument. void setArg(unsigned Arg, Expr *ArgExpr) { assert(Arg < NumArgs && "Arg access out of range!"); diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index c532b8c590..86c522795e 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -396,15 +396,22 @@ CXXConstructExpr::CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T, CallExpr::hasAnyValueDependentArguments(args, numargs))), Constructor(D), Elidable(elidable), Args(0), NumArgs(numargs) { // leave room for default arguments; - FunctionDecl *FDecl = cast<FunctionDecl>(D); - unsigned NumArgsInProto = FDecl->param_size(); - NumArgs += (NumArgsInProto - numargs); - if (NumArgs > 0) { - Args = new (C) Stmt*[NumArgs]; - for (unsigned i = 0; i < numargs; ++i) + const FunctionProtoType *FTy = + cast<FunctionDecl>(D)->getType()->getAsFunctionProtoType(); + + unsigned NumArgsInProto = FTy->getNumArgs(); + unsigned NumArgsToAllocate = FTy->isVariadic() ? NumArgs : NumArgsInProto; + if (NumArgsToAllocate) { + Args = new (C) Stmt*[NumArgsToAllocate]; + + for (unsigned i = 0; i != NumArgs; ++i) Args[i] = args[i]; - for (unsigned i = numargs; i < NumArgs; ++i) + + // Set default arguments to 0. + for (unsigned i = NumArgs; i != NumArgsToAllocate; ++i) Args[i] = 0; + + NumArgs = NumArgsToAllocate; } } |