[cfe-commits] r110891 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/destructor.cpp

John McCall rjmccall at apple.com
Wed Aug 11 17:57:17 PDT 2010


Author: rjmccall
Date: Wed Aug 11 19:57:17 2010
New Revision: 110891

URL: http://llvm.org/viewvc/llvm-project?rev=110891&view=rev
Log:
Fix a crash on invalid when declaring an implicit member of a class with an
invalid destructor.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/destructor.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=110891&r1=110890&r2=110891&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Aug 11 19:57:17 2010
@@ -3652,8 +3652,14 @@
                                     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

Modified: cfe/trunk/test/SemaCXX/destructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/destructor.cpp?rev=110891&r1=110890&r2=110891&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/destructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/destructor.cpp Wed Aug 11 19:57:17 2010
@@ -105,3 +105,17 @@
   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();
+  }
+}





More information about the cfe-commits mailing list