]> granicus.if.org Git - clang/commitdiff
When building the type of a destructor, make sure to keep the
authorDouglas Gregor <dgregor@apple.com>
Thu, 1 Jul 2010 02:33:15 +0000 (02:33 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 1 Jul 2010 02:33:15 +0000 (02:33 +0000)
exception specification. Fixes PR7526.

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

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/destructors.cpp
test/SemaCXX/destructor.cpp
www/compatibility.html

index 5588db79e372fb2f7395bb760913386f4c58a882..93e6a06ef89e19b24bcc3860f3118d91ec6176c0 100644 (file)
@@ -2672,7 +2672,7 @@ public:
   QualType CheckConstructorDeclarator(Declarator &D, QualType R,
                                       FunctionDecl::StorageClass& SC);
   void CheckConstructor(CXXConstructorDecl *Constructor);
-  QualType CheckDestructorDeclarator(Declarator &D,
+  QualType CheckDestructorDeclarator(Declarator &D, QualType R,
                                      FunctionDecl::StorageClass& SC);
   bool CheckDestructor(CXXDestructorDecl *Destructor);
   void CheckConversionDeclarator(Declarator &D, QualType &R,
index ba84f7c223350fc3ad2fa9031ba4f220744dbef1..500d73eb9b44ced67199b763f9456a6bf375976f 100644 (file)
@@ -3023,7 +3023,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   } else if (Name.getNameKind() == DeclarationName::CXXDestructorName) {
     // This is a C++ destructor declaration.
     if (DC->isRecord()) {
-      R = CheckDestructorDeclarator(D, SC);
+      R = CheckDestructorDeclarator(D, R, SC);
 
       NewFD = CXXDestructorDecl::Create(Context,
                                         cast<CXXRecordDecl>(DC),
index 1c0a72bf1183fc0069a6051ed07b5bf196061d5d..c59575f13b575993f18402c2be0974da43b29d56 100644 (file)
@@ -2990,9 +2990,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R,
 
   // Rebuild the function type "R" without any type qualifiers (in
   // case any of the errors above fired) and with "void" as the
-  // return type, since constructors don't have return types. We
-  // *always* have to do this, because GetTypeForDeclarator will
-  // put in a result type of "int" when none was specified.
+  // return type, since constructors don't have return types.
   const FunctionProtoType *Proto = R->getAs<FunctionProtoType>();
   return Context.getFunctionType(Context.VoidTy, Proto->arg_type_begin(),
                                  Proto->getNumArgs(),
@@ -3087,7 +3085,7 @@ FTIHasSingleVoidArgument(DeclaratorChunk::FunctionTypeInfo &FTI) {
 /// emit diagnostics and set the declarator to invalid.  Even if this happens,
 /// will be updated to reflect a well-formed type for the destructor and
 /// returned.
-QualType Sema::CheckDestructorDeclarator(Declarator &D,
+QualType Sema::CheckDestructorDeclarator(Declarator &D, QualType R,
                                          FunctionDecl::StorageClass& SC) {
   // C++ [class.dtor]p1:
   //   [...] A typedef-name that names a class is a class-name
@@ -3095,11 +3093,9 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D,
   //   be used as the identifier in the declarator for a destructor
   //   declaration.
   QualType DeclaratorType = GetTypeFromParser(D.getName().DestructorName);
-  if (isa<TypedefType>(DeclaratorType)) {
+  if (isa<TypedefType>(DeclaratorType))
     Diag(D.getIdentifierLoc(), diag::err_destructor_typedef_name)
       << DeclaratorType;
-    D.setInvalidType();
-  }
 
   // C++ [class.dtor]p2:
   //   A destructor is used to destroy objects of its class type. A
@@ -3113,9 +3109,10 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D,
     if (!D.isInvalidType())
       Diag(D.getIdentifierLoc(), diag::err_destructor_cannot_be)
         << "static" << SourceRange(D.getDeclSpec().getStorageClassSpecLoc())
-        << SourceRange(D.getIdentifierLoc());
+        << SourceRange(D.getIdentifierLoc())
+        << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
+    
     SC = FunctionDecl::None;
-    D.setInvalidType();
   }
   if (D.getDeclSpec().hasTypeSpecifier() && !D.isInvalidType()) {
     // Destructors don't have return types, but the parser will
@@ -3163,11 +3160,17 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D,
   // Rebuild the function type "R" without any type qualifiers or
   // parameters (in case any of the errors above fired) and with
   // "void" as the return type, since destructors don't have return
-  // types. We *always* have to do this, because GetTypeForDeclarator
-  // will put in a result type of "int" when none was specified.
-  // FIXME: Exceptions!
+  // types. 
+  const FunctionProtoType *Proto = R->getAs<FunctionProtoType>();
+  if (!Proto)
+    return QualType();
+  
   return Context.getFunctionType(Context.VoidTy, 0, 0, false, 0,
-                                 false, false, 0, 0, FunctionType::ExtInfo());
+                                 Proto->hasExceptionSpec(),
+                                 Proto->hasAnyExceptionSpec(),
+                                 Proto->getNumExceptions(),
+                                 Proto->exception_begin(),
+                                 Proto->getExtInfo());
 }
 
 /// CheckConversionDeclarator - Called by ActOnDeclarator to check the
index 1442e374039391a3618eeed04da11a86a83fb8bc..62621f6e9883c1e5693e4ea4a4bf88328aafdac3 100644 (file)
@@ -32,6 +32,17 @@ struct C {
 
 C::~C() { }
 
+namespace PR7526 {
+  extern void foo();
+  struct allocator {
+    ~allocator() throw();
+  };
+
+  // CHECK: define void @_ZN6PR75269allocatorD2Ev
+  // CHECK: call void @__cxa_call_unexpected
+  allocator::~allocator() throw() { foo(); }
+}
+
 // PR5084
 template<typename T>
 class A1 {
index ae3dc86e97f507bc58b9e306fa96f343af5f1d7e..1d36ceab236bcafd9775ce00a0dccdbd4f35fdb7 100644 (file)
@@ -19,7 +19,9 @@ struct D {
     // expected-error{{type qualifier is not allowed on this function}} \
     // expected-error{{destructor cannot be declared 'static'}}  \
     // expected-error{{destructor cannot have any parameters}}   \
-    // expected-error{{destructor cannot be variadic}}
+    // expected-error{{destructor cannot be variadic}} \
+    // expected-error{{destructor cannot have a return type}} \
+    // expected-error{{'const' qualifier is not allowed on a destructor}}
 };
 
 struct D2 {
index 85133fbca2f6ff2d539a35e7ec9328f1d0c87d6f..0f8409b953a5ff216edffde94132bbfb6ee82440 100644 (file)
@@ -590,9 +590,8 @@ void g(Base *base) {
 downcast.mm:6:3: error: no matching function for call to 'f'
   f(base);
   ^
-downcast.mm:4:6: note: candidate function not viable: cannot convert from base
-      class pointer 'Base *' to derived class pointer 'Derived *' for 1st
-      argument
+downcast.mm:4:6: note: candidate function not viable: cannot convert from
+      superclass 'Base *' to subclass 'Derived *' for 1st argument
 void f(Derived *);
      ^
 </pre>