diff options
| author | John McCall <rjmccall@apple.com> | 2010-04-22 01:10:34 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-04-22 01:10:34 +0000 |
| commit | 2e6567ae605c6b070ace32e8ecc19a36127b04f7 (patch) | |
| tree | 8f1be61c7bd59bcd6641e453f092db80222a3c3c /clang/lib/Sema | |
| parent | 4f4946aaaa194da6d19250e924305cf0c3f61248 (diff) | |
| download | bcm5719-llvm-2e6567ae605c6b070ace32e8ecc19a36127b04f7.tar.gz bcm5719-llvm-2e6567ae605c6b070ace32e8ecc19a36127b04f7.zip | |
Call PerformCopyInitialization to properly initialize the exception temporary
in a throw expression. Use EmitAnyExprToMem to emit the throw expression,
which magically elides the final copy-constructor call (which raises a new
strict-compliance bug, but baby steps). Give __cxa_throw a destructor pointer
if the exception type has a non-trivial destructor.
llvm-svn: 102039
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 5f1eee1f0a5..7df1c5683c3 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -399,10 +399,10 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) { // If the type of the exception would be an incomplete type or a pointer // to an incomplete type other than (cv) void the program is ill-formed. QualType Ty = E->getType(); - int isPointer = 0; + bool isPointer = false; if (const PointerType* Ptr = Ty->getAs<PointerType>()) { Ty = Ptr->getPointeeType(); - isPointer = 1; + isPointer = true; } if (!isPointer || !Ty->isVoidType()) { if (RequireCompleteType(ThrowLoc, Ty, @@ -415,21 +415,18 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) { PDiag(diag::err_throw_abstract_type) << E->getSourceRange())) return true; - - // FIXME: This is just a hack to mark the copy constructor referenced. - // This should go away when the next FIXME is fixed. - const RecordType *RT = Ty->getAs<RecordType>(); - if (!RT) - return false; - - const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); - if (RD->hasTrivialCopyConstructor()) - return false; - CXXConstructorDecl *CopyCtor = RD->getCopyConstructor(Context, 0); - MarkDeclarationReferenced(ThrowLoc, CopyCtor); } - // FIXME: Construct a temporary here. + // Initialize the exception result. This implicitly weeds out + // abstract types or types with inaccessible copy constructors. + InitializedEntity Entity = + InitializedEntity::InitializeException(ThrowLoc, E->getType()); + OwningExprResult Res = PerformCopyInitialization(Entity, + SourceLocation(), + Owned(E)); + if (Res.isInvalid()) + return true; + E = Res.takeAs<Expr>(); return false; } |

