diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-09 23:08:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-09 23:08:42 +0000 |
commit | 39da0b8145eaec7da7004f9b3645c5c9f4f63b1d (patch) | |
tree | 736478849d6a4c9123a029dc251b7b242111088d /lib/Sema/SemaDecl.cpp | |
parent | 84ec96c8a810df59de4052368beab29f13456707 (diff) |
Improve handling of initialization by constructor, by ensuring that
such initializations properly convert constructor arguments and fill
in default arguments where necessary. This also makes the ownership
model more clear.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81394 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d49ba890b2..9bd89ef270 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3278,7 +3278,6 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, } // C++ [dcl.init]p9: - // // If no initializer is specified for an object, and the object // is of (possibly cv-qualified) non-POD class type (or array // thereof), the object shall be default-initialized; if the @@ -3290,28 +3289,26 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, InitType = Array->getElementType(); if ((!Var->hasExternalStorage() && !Var->isExternC(Context)) && InitType->isRecordType() && !InitType->isDependentType()) { - CXXRecordDecl *RD = - cast<CXXRecordDecl>(InitType->getAs<RecordType>()->getDecl()); - CXXConstructorDecl *Constructor = 0; if (!RequireCompleteType(Var->getLocation(), InitType, - diag::err_invalid_incomplete_type_use)) - Constructor - = PerformInitializationByConstructor(InitType, 0, 0, + diag::err_invalid_incomplete_type_use)) { + ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this); + + CXXConstructorDecl *Constructor + = PerformInitializationByConstructor(InitType, + MultiExprArg(*this, 0, 0), Var->getLocation(), SourceRange(Var->getLocation(), Var->getLocation()), Var->getDeclName(), - IK_Default); - if (!Constructor) - Var->setInvalidDecl(); - else { - if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor()) { - if (InitializeVarWithConstructor(Var, Constructor, InitType, - MultiExprArg(*this))) - Var->setInvalidDecl(); - } - - FinalizeVarWithDestructor(Var, InitType); + IK_Default, + ConstructorArgs); + + if (!Constructor || + InitializeVarWithConstructor(Var, Constructor, InitType, + move_arg(ConstructorArgs))) + Var->setInvalidDecl(); + else + FinalizeVarWithDestructor(Var, InitType); } } } |