Handle default arguments when calling copy constructors for bases or members when synthesizing a copy constructor. Fixes PR6628.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99864 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Carlsson 2010-03-30 02:57:48 +00:00
Родитель d09020d87a
Коммит 46bbf8d352
2 изменённых файлов: 63 добавлений и 0 удалений

Просмотреть файл

@ -549,10 +549,30 @@ void CodeGenFunction::EmitClassMemberwiseCopy(
// Push the Src ptr.
CallArgs.push_back(std::make_pair(RValue::get(Src),
BaseCopyCtor->getParamDecl(0)->getType()));
unsigned OldNumLiveTemporaries = LiveTemporaries.size();
// If the copy constructor has default arguments, emit them.
for (unsigned I = 1, E = BaseCopyCtor->getNumParams(); I < E; ++I) {
const ParmVarDecl *Param = BaseCopyCtor->getParamDecl(I);
const Expr *DefaultArgExpr = Param->getDefaultArg();
assert(DefaultArgExpr && "Ctor parameter must have default arg!");
QualType ArgType = Param->getType();
CallArgs.push_back(std::make_pair(EmitCallArg(DefaultArgExpr, ArgType),
ArgType));
}
const FunctionProtoType *FPT =
BaseCopyCtor->getType()->getAs<FunctionProtoType>();
EmitCall(CGM.getTypes().getFunctionInfo(CallArgs, FPT),
Callee, ReturnValueSlot(), CallArgs, BaseCopyCtor);
// Pop temporaries.
while (LiveTemporaries.size() > OldNumLiveTemporaries)
PopCXXTemporary();
}
}

Просмотреть файл

@ -110,3 +110,46 @@ struct B : A {
void f(const B &b1) {
B b2(b1);
}
// PR6628
namespace PR6628 {
struct T {
T();
~T();
double d;
};
struct A {
A(const A &other, const T &t = T(), const T& t2 = T());
};
struct B : A {
A a1;
A a2;
};
// Force the copy constructor to be synthesized.
void f(B b1) {
B b2 = b1;
}
// CHECK: define linkonce_odr void @_ZN6PR66281BC2ERKS0_
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281AC2ERKS0_RKNS_1TES5_
// CHECK: call void @_ZN6PR66281TD1Ev
// CHECK: call void @_ZN6PR66281TD1Ev
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_
// CHECK: call void @_ZN6PR66281TD1Ev
// CHECK: call void @_ZN6PR66281TD1Ev
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281TC1Ev
// CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_
// CHECK: call void @_ZN6PR66281TD1Ev
// CHECK: call void @_ZN6PR66281TD1Ev
}