]> granicus.if.org Git - clang/commitdiff
Perform a very, very ugly song-and-dance number to free the
authorDouglas Gregor <dgregor@apple.com>
Fri, 27 Mar 2009 23:25:45 +0000 (23:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 27 Mar 2009 23:25:45 +0000 (23:25 +0000)
NestedNameSpecifiers without causing problems for the FoldingSet that
contains them.

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

lib/AST/ASTContext.cpp

index 2956460684cf9306f7bea818a45f62ce0668f239..76671576cee9d093289e14772b3a3271515e7df7 100644 (file)
@@ -78,17 +78,22 @@ ASTContext::~ASTContext() {
   }
 
   // Destroy nested-name-specifiers.
-  for (llvm::FoldingSet<NestedNameSpecifier>::iterator 
-         NNS = NestedNameSpecifiers.begin(),
-         NNSEnd = NestedNameSpecifiers.end(); 
-       NNS != NNSEnd; ) {
-    // This loop iterates, then destroys so that it doesn't cause invalid
-    // reads.
-    // FIXME: Find a less fragile way to do this!
-    NestedNameSpecifier* N = &*NNS;
-    ++NNS;
-    N->Destroy(*this);
-  }
+  llvm::SmallVector<NestedNameSpecifier *, 16> NestedNameSpecs; 
+  {
+    for (llvm::FoldingSet<NestedNameSpecifier>::iterator
+           NNS = NestedNameSpecifiers.begin(),
+           NNSEnd = NestedNameSpecifiers.end(); 
+         NNS != NNSEnd; 
+         ++NNS)
+      NestedNameSpecs.push_back(&*NNS);
+  }
+  NestedNameSpecifiers.clear();
+  for (llvm::SmallVector<NestedNameSpecifier *, 16>::iterator
+         NNS = NestedNameSpecs.begin(),
+         NNSEnd = NestedNameSpecs.end(); 
+       NNS != NNSEnd; 
+       ++NNS)
+    (*NNS)->Destroy(*this);
 
   if (GlobalNestedNameSpecifier)
     GlobalNestedNameSpecifier->Destroy(*this);