<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Times;
        panose-1:2 2 6 3 5 4 5 2 3 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;
-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Hi Dale,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I looked deeper into it and your patch is
excellent I think. Thanks.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The STL documentation is indeed a bit unclear.
After a bit of Googling it looks like a lot of people faced this issue. But the
documentation doesn’t define what the iterator points to after the erase,
so logically it is invalidated as well. There’s one trick get predictable
behavior in a convenient way though:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>v.erase(i--);<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The post-decrement moves the iterator to
the previous element (which will remain valid) before the erase call, while actually
still returning the iterator to the element we want to erase.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Cheers,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Nicolas<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Dale Johannesen<br>
<b><span style='font-weight:bold'>Sent:</span></b> Friday, 23 May, 2008 19:20<br>
<b><span style='font-weight:bold'>To:</span></b> LLVM Developers Mailing List<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [LLVMdev] Iterator
issue in BranchFolder::RemoveBlocksWithHash?</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>On May 23, 2008, at 4:10 AM, Nicolas Capens wrote:<o:p></o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><br>
<br>
<o:p></o:p></span></font></p>

<span style='orphans: 2;text-align:auto;widows: 2;-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto;-webkit-text-stroke-width: 0;word-spacing:0px'>

<div link=blue vlink=purple>

<div>

<div>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'>Hi all,<o:p></o:p></span></font></p>

<u1:p></u1:p></div>

<div><u1:p>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'> <o:p></o:p></span></font></p>

</u1:p></div>

<div>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'>I updated from 2.2 to the latest SVN head
and I now get a debug assert in<span class=apple-converted-space> </span></span></font><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>BranchFolder::RemoveBlocksWithHash</span></font><font
size=2 color=black face=Arial><span style='font-size:11.0pt;font-family:Arial;
color:black'>: “vector iterators incompatible”. I’m using
Visual C++ 2005. I think this is the culprit code:<o:p></o:p></span></font></p>

<u1:p></u1:p></div>

<div><u1:p>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'> <o:p></o:p></span></font></p>

</u1:p></div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>   
MergePotentials.erase(CurMPIter);<u1:p></u1:p></span></font><font size=2
color=black face=Arial><span style='font-size:11.0pt;font-family:Arial;
color:black'><o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>   <span
class=apple-converted-space> </span></span></font><font size=2 color=blue
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:blue'>if</span></font><span class=apple-converted-space><font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'> </span></font></span><font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>(CurMPIter==B)<u1:p></u1:p></span></font><font size=2 color=black
face=Arial><span style='font-size:11.0pt;font-family:Arial;color:black'><o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>     <span
class=apple-converted-space> </span></span></font><font size=2 color=blue
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:blue'>break</span></font><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></font><font
size=2 color=black face=Arial><span style='font-size:11.0pt;font-family:Arial;
color:black'><o:p></o:p></span></font></p>

<u1:p></u1:p></div>

<div><u1:p>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'> <o:p></o:p></span></font></p>

</u1:p></div>

<div>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'>The erase clears the _Mycont field (i.e.
the iterator’s container), while the == expects CurMPIter and B to have
the same container. I’m no STL guru but it seems wrong to first erase an
element and then try to compare it. I traced it back to revision 50921 made on
May 10’th. I rewrote it like following, which I’m not entirely sure
is the intended behavior but it ‘works for me’:<o:p></o:p></span></font></p>

<u1:p></u1:p></div>

<div><u1:p>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
11.0pt;font-family:Arial;color:black'> <o:p></o:p></span></font></p>

</u1:p></div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>   
CurMPIter = MergePotentials.erase(CurMPIter);<u1:p></u1:p></span></font><font
size=2 color=black face=Arial><span style='font-size:11.0pt;font-family:Arial;
color:black'><o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>   <span
class=apple-converted-space> </span></span></font><font size=2 color=blue
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:blue'>if</span></font><span class=apple-converted-space><font size=2
color=black face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'> </span></font></span><font size=2 color=black
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:black'>(CurMPIter==B)<u1:p></u1:p></span></font><font size=2 color=black
face=Arial><span style='font-size:11.0pt;font-family:Arial;color:black'><o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>     <span
class=apple-converted-space> </span></span></font><font size=2 color=blue
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New";
color:blue'>break</span></font><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>;</span></font><font
size=2 color=black face=Arial><span style='font-size:11.0pt;font-family:Arial;
color:black'><o:p></o:p></span></font></p>

</div>

</div>

</div>

</span>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Thanks for analyzing the problem.<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I also am not a STL guru; the standard says erase<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><span class=apple-style-span><font size=4 face=Times><span
style='font-size:13.0pt;font-family:Times'>"Invalidates all the iterators
and references after the point of the erase"</span></font></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-style-span><font size=3 face=Helvetica><span
style='font-size:12.0pt;font-family:Helvetica'>which is not wonderfully worded,
but I take it to mean an iterator referring <b><span style='font-weight:
bold'>to</span></b> the point of the erase remains valid....But if it doesn't
work that way on VC++, it doesn't.  Now I know.</span></font></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>It's clearly better to call erase only once, so I've rewritten it that
way.   Please make sure it works for you.<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

</div>

</div>

</body>

</html>