]> granicus.if.org Git - clang/commitdiff
Template instantiation for destructors. This is somewhat repetitive;
authorDouglas Gregor <dgregor@apple.com>
Tue, 24 Mar 2009 00:15:49 +0000 (00:15 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 24 Mar 2009 00:15:49 +0000 (00:15 +0000)
eliminating the duplication is next on the list.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67579 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-method.cpp

index d8e526c6028f5ba566c7a90a8481d61502dfed05..d9247133490a528cce547ef07368cf255ab64175 100644 (file)
@@ -44,9 +44,9 @@ namespace {
     Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
     Decl *VisitEnumDecl(EnumDecl *D);
     Decl *VisitCXXMethodDecl(CXXMethodDecl *D);
+    Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D);
     Decl *VisitParmVarDecl(ParmVarDecl *D);
     Decl *VisitOriginalParmVarDecl(OriginalParmVarDecl *D);
-
     // Base case. FIXME: Remove once we can instantiate everything.
     Decl *VisitDecl(Decl *) { 
       return 0;
@@ -265,6 +265,48 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D) {
   return Method;
 }
 
+Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
+  QualType T = SemaRef.InstantiateType(D->getType(), TemplateArgs,
+                                       NumTemplateArgs, D->getLocation(),
+                                       D->getDeclName());
+  if (T.isNull())
+    return 0;
+  
+  // Build the instantiated destructor declaration.
+  CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
+  QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
+  CXXDestructorDecl *Destructor
+    = CXXDestructorDecl::Create(SemaRef.Context, Record,
+                                D->getLocation(),
+             SemaRef.Context.DeclarationNames.getCXXDestructorName(ClassTy),
+                                T, D->isInline(), false);
+
+  Destructor->setAccess(D->getAccess());
+  // FIXME: Duplicates some logic in ActOnFunctionDeclarator,
+  // VisitCXXDestructorDecl.
+  if (D->isVirtual()) {
+    Destructor->setVirtual();
+    Record->setAggregate(false);
+    Record->setPOD(false);
+    Record->setPolymorphic(true);
+  }
+  if (D->isDeleted())
+    Destructor->setDeleted();
+  if (D->isPure()) {
+    Destructor->setPure();
+    Record->setAbstract(true);
+  }
+
+  bool Redeclaration = false;
+  bool OverloadableAttrRequired = false;
+  NamedDecl *PrevDecl = 0;
+  if (SemaRef.CheckFunctionDeclaration(Destructor, PrevDecl, Redeclaration,
+                                       /*FIXME:*/OverloadableAttrRequired))
+    Destructor->setInvalidDecl();
+  Owner->addDecl(Destructor);
+  return Destructor;
+}
+
 Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
   QualType OrigT = SemaRef.InstantiateType(D->getOriginalType(), TemplateArgs,
                                            NumTemplateArgs, D->getLocation(),
index 2eb2b7a88cde7fb7ad03021afbeb1024bfaca34f..a6a62354657c60d0b11593a41193c805d0309abd 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: clang -fsyntax-only -verify %s
-
 template<typename T>
 class X {
 public:
@@ -41,3 +40,12 @@ void test_ovl(Overloading<int, long> *oil, int i, long l) {
 void test_ovl_bad() {
   Overloading<float, float> off; // expected-note{{in instantiation of template class 'class Overloading<float, float>' requested here}}
 }
+
+template<typename T>
+class HasDestructor {
+  virtual ~HasDestructor() = 0;
+};
+
+int i = sizeof(HasDestructor<int>); // FIXME: forces instantiation, but 
+                // the code below should probably instantiate by itself.
+int abstract_destructor[__is_abstract(HasDestructor<int>)? 1 : -1];