]> granicus.if.org Git - clang/commitdiff
Fix a crash on invalid when declaring an implicit member of a class with an
authorJohn McCall <rjmccall@apple.com>
Thu, 12 Aug 2010 00:57:17 +0000 (00:57 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 12 Aug 2010 00:57:17 +0000 (00:57 +0000)
invalid destructor.

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

lib/Sema/SemaDecl.cpp
test/SemaCXX/destructor.cpp

index de7ad3d791d46bab3a6d7b46abcac200f8cbc014..b27f727b3c5e2eee8c8afb02829c17677ca03ca3 100644 (file)
@@ -3652,8 +3652,14 @@ void Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
                                     bool &Redeclaration,
                                     bool &OverloadableAttrRequired) {
   // If NewFD is already known erroneous, don't do any of this checking.
-  if (NewFD->isInvalidDecl())
+  if (NewFD->isInvalidDecl()) {
+    // If this is a class member, mark the class invalid immediately.
+    // This avoids some consistency errors later.
+    if (isa<CXXMethodDecl>(NewFD))
+      cast<CXXMethodDecl>(NewFD)->getParent()->setInvalidDecl();
+
     return;
+  }
 
   if (NewFD->getResultType()->isVariablyModifiedType()) {
     // Functions returning a variably modified type violate C99 6.7.5.2p2
index 1502f7347128121396a39408d6d355bbf89492e5..cdcae2e4119e8c8cb446cfd73521dec277b4df2d 100644 (file)
@@ -105,3 +105,17 @@ namespace test6 {
   class B : A<int> { B(); };
   B::B() {} // expected-note {{in instantiation of member function 'test6::A<int>::~A' requested here}}
 }
+
+// Make sure classes are marked invalid when they have invalid
+// members.  This avoids a crash-on-invalid.
+namespace test7 {
+  struct A {
+    ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}}
+  };
+  struct B : A {};
+
+  void test() {
+    B *b;
+    b->~B();
+  }
+}