summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-09 23:08:42 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-09 23:08:42 +0000
commit5d3507d39cb6d58bd5e46bc9194972c9b00545a9 (patch)
treec823c040b2888bd3b09cbcee2d3db58f6de2e9c3 /clang/lib/Sema/SemaInit.cpp
parentaec990efd72473be9cb6bbbfed4cc3c79dba84ef (diff)
downloadbcm5719-llvm-5d3507d39cb6d58bd5e46bc9194972c9b00545a9.tar.gz
bcm5719-llvm-5d3507d39cb6d58bd5e46bc9194972c9b00545a9.zip
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. llvm-svn: 81394
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r--clang/lib/Sema/SemaInit.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c1f7716330f..328609a1929 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -172,18 +172,23 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
if (RD->hasTrivialConstructor() && RD->hasTrivialDestructor())
return false;
+ ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
+
CXXConstructorDecl *Constructor
- = PerformInitializationByConstructor(DeclType, &Init, 1,
- InitLoc, Init->getSourceRange(),
- InitEntity,
- DirectInit? IK_Direct : IK_Copy);
+ = PerformInitializationByConstructor(DeclType,
+ MultiExprArg(*this,
+ (void **)&Init, 1),
+ InitLoc, Init->getSourceRange(),
+ InitEntity,
+ DirectInit? IK_Direct : IK_Copy,
+ ConstructorArgs);
if (!Constructor)
return true;
OwningExprResult InitResult =
BuildCXXConstructExpr(/*FIXME:ConstructLoc*/SourceLocation(),
DeclType, Constructor,
- MultiExprArg(*this, (void**)&Init, 1));
+ move_arg(ConstructorArgs));
if (InitResult.isInvalid())
return true;
@@ -1810,13 +1815,28 @@ bool Sema::CheckValueInitialization(QualType Type, SourceLocation Loc) {
// constructor (12.1), then the default constructor for T is
// called (and the initialization is ill-formed if T has no
// accessible default constructor);
- if (ClassDecl->hasUserDeclaredConstructor())
- // FIXME: Eventually, we'll need to put the constructor decl into the
- // AST.
- return PerformInitializationByConstructor(Type, 0, 0, Loc,
- SourceRange(Loc),
- DeclarationName(),
- IK_Direct);
+ if (ClassDecl->hasUserDeclaredConstructor()) {
+ ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
+
+ CXXConstructorDecl *Constructor
+ = PerformInitializationByConstructor(Type,
+ MultiExprArg(*this, 0, 0),
+ Loc, SourceRange(Loc),
+ DeclarationName(),
+ IK_Direct,
+ ConstructorArgs);
+ if (!Constructor)
+ return true;
+
+ OwningExprResult Init
+ = BuildCXXConstructExpr(Loc, Type, Constructor,
+ move_arg(ConstructorArgs));
+ if (Init.isInvalid())
+ return true;
+
+ // FIXME: Actually perform the value-initialization!
+ return false;
+ }
}
}
OpenPOWER on IntegriCloud