diff options
author | Anders Carlsson <andersca@mac.com> | 2010-03-30 02:57:48 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-03-30 02:57:48 +0000 |
commit | 46bbf8d352fcd615420c5759a112ccd6e61516ad (patch) | |
tree | 1403f6030729bdce747e1587d1796695d8b1e677 | |
parent | d09020d87a69803b02c68eb6bf0b38e6ca660eda (diff) |
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
-rw-r--r-- | lib/CodeGen/CGClass.cpp | 20 | ||||
-rw-r--r-- | test/CodeGenCXX/copy-constructor-synthesis.cpp | 43 |
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index ebefba2411..8d565f6d41 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -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(); } } diff --git a/test/CodeGenCXX/copy-constructor-synthesis.cpp b/test/CodeGenCXX/copy-constructor-synthesis.cpp index 35bd83a7d0..3af40cb4ec 100644 --- a/test/CodeGenCXX/copy-constructor-synthesis.cpp +++ b/test/CodeGenCXX/copy-constructor-synthesis.cpp @@ -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 +} + |