diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-10-27 16:51:19 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-10-27 16:51:19 +0000 |
commit | 115654873df4ccabe8c0515a898034d1f72cef8d (patch) | |
tree | 0f40417b7a3eb8d0de133dfb2f60b05d2954c93c /clang/lib/Sema/SemaExprCXX.cpp | |
parent | 50b41ed06008b2a129838a1fdbf037ad2bc8087a (diff) | |
download | bcm5719-llvm-115654873df4ccabe8c0515a898034d1f72cef8d.tar.gz bcm5719-llvm-115654873df4ccabe8c0515a898034d1f72cef8d.zip |
Generate constructor for value-initialization cases, even if the
implementation technique doesn't call the constructor at that point.
DR302. Fixes pr5296.
llvm-svn: 85249
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 8e3fbda67c5..d5f93dce280 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -288,7 +288,20 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, << FullRange); assert(NumExprs == 0 && "Expected 0 expressions"); - + + if (const RecordType *Record = Ty->getAs<RecordType>()) { + if (!Record->getDecl()->isUnion()) { + // As clarified in C++ DR302, generate constructor for + // value-initialization cases, even if the implementation technique + // doesn't call the constructor at that point. + ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this); + (void)PerformInitializationByConstructor(Ty, MultiExprArg(*this, 0, 0), + TypeRange.getBegin(), + TypeRange, DeclarationName(), + IK_Default, ConstructorArgs); + } + } + // C++ [expr.type.conv]p2: // The expression T(), where T is a simple-type-specifier for a non-array // complete object type or the (possibly cv-qualified) void type, creates an @@ -489,7 +502,21 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, return ExprError(Diag(StartLoc, diag::err_new_uninitialized_const) << TypeRange); } else if (NumConsArgs == 0) { - // Object is value-initialized. Do nothing. + // Object is value-initialized. + if (const RecordType *Record = AllocType->getAs<RecordType>()) { + if (!Record->getDecl()->isUnion()) { + // As clarified in C++ DR302, generate constructor for + // value-initialization cases, even if the implementation technique + // doesn't call the constructor at that point. + ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this); + (void)PerformInitializationByConstructor(AllocType, + MultiExprArg(*this, 0, 0), + TypeRange.getBegin(), + TypeRange, DeclarationName(), + IK_Default, + ConstructorArgs); + } + } } else if (NumConsArgs == 1) { // Object is direct-initialized. // FIXME: What DeclarationName do we pass in here? |