[cfe-commits] r107415 - in /cfe/trunk/lib/Sema: Sema.h SemaDeclCXX.cpp

Douglas Gregor dgregor at apple.com
Thu Jul 1 12:09:28 PDT 2010


Author: dgregor
Date: Thu Jul  1 14:09:28 2010
New Revision: 107415

URL: http://llvm.org/viewvc/llvm-project?rev=107415&view=rev
Log:
Move the implicit declaration of a constructor out to a separate
method. No functionality change.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=107415&r1=107414&r2=107415&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Jul  1 14:09:28 2010
@@ -2225,10 +2225,22 @@
   void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
                                         CXXConstructorDecl *Constructor);
 
+  /// \brief Declare the implicit destructor for the given class.
+  ///
+  /// \param S The scope of the class, which may be NULL if this is a 
+  /// template instantiation.
+  ///
+  /// \param ClassDecl The class declaration into which the implicit 
+  /// destructor will be added.
+  ///
+  /// \returns The implicitly-declared destructor.
+  CXXDestructorDecl *DeclareImplicitDestructor(Scope *S, 
+                                               CXXRecordDecl *ClassDecl);
+                                               
   /// DefineImplicitDestructor - Checks for feasibility of
   /// defining this destructor as the default destructor.
   void DefineImplicitDestructor(SourceLocation CurrentLocation,
-                                        CXXDestructorDecl *Destructor);
+                                CXXDestructorDecl *Destructor);
 
   /// \brief Declare the implicit copy constructor for the given class.
   ///

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=107415&r1=107414&r2=107415&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jul  1 14:09:28 2010
@@ -2698,73 +2698,8 @@
   if (!ClassDecl->hasUserDeclaredCopyAssignment())
     DeclareImplicitCopyAssignment(S, ClassDecl);
 
-  if (!ClassDecl->hasUserDeclaredDestructor()) {
-    // C++ [class.dtor]p2:
-    //   If a class has no user-declared destructor, a destructor is
-    //   declared implicitly. An implicitly-declared destructor is an
-    //   inline public member of its class.
-    
-    // C++ [except.spec]p14: 
-    //   An implicitly declared special member function (Clause 12) shall have 
-    //   an exception-specification.
-    ImplicitExceptionSpecification ExceptSpec(Context);
-    
-    // Direct base-class destructors.
-    for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(),
-                                         BEnd = ClassDecl->bases_end();
-         B != BEnd; ++B) {
-      if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
-        ExceptSpec.CalledDecl(
-                    cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
-    }
-         
-    // Virtual base-class destructors.
-    for (CXXRecordDecl::base_class_iterator B = ClassDecl->vbases_begin(),
-                                         BEnd = ClassDecl->vbases_end();
-         B != BEnd; ++B) {
-      if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
-        ExceptSpec.CalledDecl(
-                    cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
-    }
-
-    // Field destructors.
-    for (RecordDecl::field_iterator F = ClassDecl->field_begin(),
-                                 FEnd = ClassDecl->field_end();
-         F != FEnd; ++F) {
-      if (const RecordType *RecordTy
-                = Context.getBaseElementType(F->getType())->getAs<RecordType>())
-        ExceptSpec.CalledDecl(
-                    cast<CXXRecordDecl>(RecordTy->getDecl())->getDestructor());
-    }
-    
-    QualType Ty = Context.getFunctionType(Context.VoidTy,
-                                          0, 0, false, 0,
-                                        ExceptSpec.hasExceptionSpecification(),
-                                      ExceptSpec.hasAnyExceptionSpecification(),
-                                          ExceptSpec.size(),
-                                          ExceptSpec.data(),
-                                          FunctionType::ExtInfo());
-
-    DeclarationName Name
-      = Context.DeclarationNames.getCXXDestructorName(ClassType);
-    CXXDestructorDecl *Destructor
-      = CXXDestructorDecl::Create(Context, ClassDecl,
-                                  ClassDecl->getLocation(), Name, Ty,
-                                  /*isInline=*/true,
-                                  /*isImplicitlyDeclared=*/true);
-    Destructor->setAccess(AS_public);
-    Destructor->setImplicit();
-    Destructor->setTrivial(ClassDecl->hasTrivialDestructor());
-    if (S)
-      PushOnScopeChains(Destructor, S, true);
-    else
-      ClassDecl->addDecl(Destructor);
-
-    // This could be uniqued if it ever proves significant.
-    Destructor->setTypeSourceInfo(Context.getTrivialTypeSourceInfo(Ty));
-    
-    AddOverriddenMethods(ClassDecl, Destructor);
-  }
+  if (!ClassDecl->hasUserDeclaredDestructor())
+    DeclareImplicitDestructor(S, ClassDecl);
 }
 
 void Sema::ActOnReenterTemplateScope(Scope *S, DeclPtrTy TemplateD) {
@@ -4255,6 +4190,81 @@
   }
 }
 
+CXXDestructorDecl *Sema::DeclareImplicitDestructor(Scope *S, 
+                                                   CXXRecordDecl *ClassDecl) {
+  // C++ [class.dtor]p2:
+  //   If a class has no user-declared destructor, a destructor is
+  //   declared implicitly. An implicitly-declared destructor is an
+  //   inline public member of its class.
+  
+  // C++ [except.spec]p14: 
+  //   An implicitly declared special member function (Clause 12) shall have 
+  //   an exception-specification.
+  ImplicitExceptionSpecification ExceptSpec(Context);
+  
+  // Direct base-class destructors.
+  for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(),
+                                       BEnd = ClassDecl->bases_end();
+       B != BEnd; ++B) {
+    if (B->isVirtual()) // Handled below.
+      continue;
+    
+    if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
+      ExceptSpec.CalledDecl(
+                    cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
+  }
+  
+  // Virtual base-class destructors.
+  for (CXXRecordDecl::base_class_iterator B = ClassDecl->vbases_begin(),
+                                       BEnd = ClassDecl->vbases_end();
+       B != BEnd; ++B) {
+    if (const RecordType *BaseType = B->getType()->getAs<RecordType>())
+      ExceptSpec.CalledDecl(
+                    cast<CXXRecordDecl>(BaseType->getDecl())->getDestructor());
+  }
+  
+  // Field destructors.
+  for (RecordDecl::field_iterator F = ClassDecl->field_begin(),
+                               FEnd = ClassDecl->field_end();
+       F != FEnd; ++F) {
+    if (const RecordType *RecordTy
+        = Context.getBaseElementType(F->getType())->getAs<RecordType>())
+      ExceptSpec.CalledDecl(
+                    cast<CXXRecordDecl>(RecordTy->getDecl())->getDestructor());
+  }
+  
+  QualType Ty = Context.getFunctionType(Context.VoidTy,
+                                        0, 0, false, 0,
+                                        ExceptSpec.hasExceptionSpecification(),
+                                    ExceptSpec.hasAnyExceptionSpecification(),
+                                        ExceptSpec.size(),
+                                        ExceptSpec.data(),
+                                        FunctionType::ExtInfo());
+  
+  CanQualType ClassType
+    = Context.getCanonicalType(Context.getTypeDeclType(ClassDecl));
+  DeclarationName Name
+    = Context.DeclarationNames.getCXXDestructorName(ClassType);
+  CXXDestructorDecl *Destructor
+    = CXXDestructorDecl::Create(Context, ClassDecl,
+                                ClassDecl->getLocation(), Name, Ty,
+                                /*isInline=*/true,
+                                /*isImplicitlyDeclared=*/true);
+  Destructor->setAccess(AS_public);
+  Destructor->setImplicit();
+  Destructor->setTrivial(ClassDecl->hasTrivialDestructor());
+  if (S)
+    PushOnScopeChains(Destructor, S, true);
+  else
+    ClassDecl->addDecl(Destructor);
+  
+  // This could be uniqued if it ever proves significant.
+  Destructor->setTypeSourceInfo(Context.getTrivialTypeSourceInfo(Ty));
+  
+  AddOverriddenMethods(ClassDecl, Destructor);
+  return Destructor;
+}
+
 void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation,
                                     CXXDestructorDecl *Destructor) {
   assert((Destructor->isImplicit() && !Destructor->isUsed(false)) &&





More information about the cfe-commits mailing list