Fix argument-passing bugs in a call to object
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62147 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index be1a27e..c66db17 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -3542,25 +3542,31 @@
ResultTy, RParenLoc));
delete [] MethodArgs;
+ // We may have default arguments. If so, we need to allocate more
+ // slots in the call for them.
+ if (NumArgs < NumArgsInProto)
+ TheCall->setNumArgs(NumArgsInProto + 1);
+ else if (NumArgs > NumArgsInProto)
+ NumArgsToCheck = NumArgsInProto;
+
// Initialize the implicit object parameter.
- if (!PerformObjectArgumentInitialization(Object, Method))
+ if (PerformObjectArgumentInitialization(Object, Method))
return true;
TheCall->setArg(0, Object);
// Check the argument types.
for (unsigned i = 0; i != NumArgsToCheck; i++) {
- QualType ProtoArgType = Proto->getArgType(i);
-
Expr *Arg;
- if (i < NumArgs)
+ if (i < NumArgs) {
Arg = Args[i];
- else
+
+ // Pass the argument.
+ QualType ProtoArgType = Proto->getArgType(i);
+ if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
+ return true;
+ } else {
Arg = new CXXDefaultArgExpr(Method->getParamDecl(i));
- QualType ArgType = Arg->getType();
-
- // Pass the argument.
- if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
- return true;
+ }
TheCall->setArg(i + 1, Arg);
}