<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">On Sat, 14 Apr 2018, 04:22 Richard Trieu via cfe-commits, <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I was tracking down a similar issue to the lldb issue before noticing the change was reverted.  The bad change that lead to it is:<br><div><br></div><div><div>     // Load pending declaration chains.</div><div>-    for (unsigned I = 0; I != PendingDeclChains.size(); ++I)</div><div>-      loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second);</div><div>+    for (const auto &I : PendingDeclChains)</div><div>+      loadPendingDeclChain(I.first, I.second);</div><div>     PendingDeclChains.clear();</div></div><div><br></div><div>Although the two looks like similar, the vector PendingDeclChains is a class member and gets new elements during loop runs.  Once enough elements are added to the vector, it get reallocated to a larger memory, but the loop is still trying to process the old, now freed, memory.  Using an index and checking the size every loop is the right way to process this vector.</div></div><div class="gmail_quote"><div dir="ltr"></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Should clang-tidy handle this type of loop differently?</div><div dir="auto"><br style="font-family:sans-serif"><div data-smartmail="gmail_signature" style="font-family:sans-serif" dir="auto">-- <br>Malcolm Parsons</div></div></div>