[cfe-commits] r67579 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-method.cpp

Douglas Gregor dgregor at apple.com
Mon Mar 23 17:15:49 PDT 2009


Author: dgregor
Date: Mon Mar 23 19:15:49 2009
New Revision: 67579

URL: http://llvm.org/viewvc/llvm-project?rev=67579&view=rev
Log:
Template instantiation for destructors. This is somewhat repetitive;
eliminating the duplication is next on the list.


Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-method.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=67579&r1=67578&r2=67579&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Mar 23 19:15:49 2009
@@ -44,9 +44,9 @@
     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 @@
   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(),

Modified: cfe/trunk/test/SemaTemplate/instantiate-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-method.cpp?rev=67579&r1=67578&r2=67579&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-method.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-method.cpp Mon Mar 23 19:15:49 2009
@@ -1,5 +1,4 @@
 // RUN: clang -fsyntax-only -verify %s
-
 template<typename T>
 class X {
 public:
@@ -41,3 +40,12 @@
 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];





More information about the cfe-commits mailing list