Fix a subtle bug in DeclContext::DestroyDecls().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62205 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 7363bd0..860a65a 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -88,6 +88,7 @@
case CXXRecord: return "CXXRecord";
case Enum: return "Enum";
case Block: return "Block";
+ case Field: return "Field";
}
}
@@ -405,10 +406,13 @@
}
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;
}
}