]> granicus.if.org Git - clang/commitdiff
Fix a subtle bug in DeclContext::DestroyDecls().
authorSteve Naroff <snaroff@apple.com>
Wed, 14 Jan 2009 01:27:31 +0000 (01:27 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 14 Jan 2009 01:27:31 +0000 (01:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62205 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclBase.cpp

index 7363bd02478809be48882177e551a70f84b9b931..860a65a1e3e117bed41596949c963f9591bbb829 100644 (file)
@@ -88,6 +88,7 @@ const char *Decl::getDeclKindName() const {
   case CXXRecord:           return "CXXRecord";
   case Enum:                return "Enum";
   case Block:               return "Block";
+  case Field:               return "Field";
   }
 }
 
@@ -405,10 +406,13 @@ DeclContext::~DeclContext() {
 }
 
 void DeclContext::DestroyDecls(ASTContext &C) {
-  for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
-    // FIXME: assert that this condition holds.
-    if ((*D)->getLexicalDeclContext() == this)
-      (*D)->Destroy(C);
+  for (decl_iterator D = decls_begin(); D != decls_end(); ) {
+   // FIXME: assert that this condition holds.
+   if ((*D)->getLexicalDeclContext() == this)
+     // Advance the cursor (via NextDeclInScope) *before* doing the Destroy.
+     (*D++)->Destroy(C);
+   else
+     ++D;
   }
 }