summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-07-02 20:37:36 +0000
committerDouglas Gregor <dgregor@apple.com>2010-07-02 20:37:36 +0000
commit7454c563f192c75fa31c123af50e15eb32000423 (patch)
treecb6a0b13191c7de2f54608877f3f0114c9d223d7 /clang/lib/Sema/SemaDeclCXX.cpp
parent0ce84486c382b9377ebeb993b0c262a70c72350a (diff)
downloadbcm5719-llvm-7454c563f192c75fa31c123af50e15eb32000423.tar.gz
bcm5719-llvm-7454c563f192c75fa31c123af50e15eb32000423.zip
Lazily declare the implicitly-declared destructor in a C++ class.
llvm-svn: 107510
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7ba34a5fead..32999995363 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2662,8 +2662,16 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) {
if (!ClassDecl->hasUserDeclaredCopyAssignment())
DeclareImplicitCopyAssignment(ClassDecl);
- if (!ClassDecl->hasUserDeclaredDestructor())
- DeclareImplicitDestructor(ClassDecl);
+ if (!ClassDecl->hasUserDeclaredDestructor()) {
+ ++ASTContext::NumImplicitDestructors;
+
+ // If we have a dynamic class, then the destructor may be virtual, so we
+ // have to declare the destructor immediately. This ensures that, e.g., it
+ // shows up in the right place in the vtable and that we diagnose problems
+ // with the implicit exception specification.
+ if (ClassDecl->isDynamicClass())
+ DeclareImplicitDestructor(ClassDecl);
+ }
}
void Sema::ActOnReenterTemplateScope(Scope *S, DeclPtrTy TemplateD) {
@@ -4274,6 +4282,7 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(CXXRecordDecl *ClassDecl) {
LookupDestructor(cast<CXXRecordDecl>(RecordTy->getDecl())));
}
+ // Create the actual destructor declaration.
QualType Ty = Context.getFunctionType(Context.VoidTy,
0, 0, false, 0,
ExceptSpec.hasExceptionSpecification(),
@@ -4294,15 +4303,21 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(CXXRecordDecl *ClassDecl) {
Destructor->setAccess(AS_public);
Destructor->setImplicit();
Destructor->setTrivial(ClassDecl->hasTrivialDestructor());
+
+ // Note that we have declared this destructor.
+ ClassDecl->setDeclaredDestructor(true);
+ ++ASTContext::NumImplicitDestructorsDeclared;
+
+ // Introduce this destructor into its scope.
if (Scope *S = getScopeForContext(ClassDecl))
- PushOnScopeChains(Destructor, S, true);
- else
- ClassDecl->addDecl(Destructor);
+ PushOnScopeChains(Destructor, S, false);
+ ClassDecl->addDecl(Destructor);
// This could be uniqued if it ever proves significant.
Destructor->setTypeSourceInfo(Context.getTrivialTypeSourceInfo(Ty));
AddOverriddenMethods(ClassDecl, Destructor);
+
return Destructor;
}
OpenPOWER on IntegriCloud