From: Steve Naroff Date: Wed, 14 Jan 2009 01:27:31 +0000 (+0000) Subject: Fix a subtle bug in DeclContext::DestroyDecls(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c92fea0c838e0df95f7aa53c0c592b659ea1b10;p=clang 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 7363bd0247..860a65a1e3 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -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; } }