<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I just make a clearer example.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str1 = str + </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">..&lt;str1.</span><span style="color:rgb(112,61,170)">endIndex</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style=""> = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="">//fatal error: cannot increment endIndex</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style=""><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">It seams that </font><font face="Menlo"><span style="font-size:11px">range.</span></font><span style="font-family:georgia,serif">startIndex internally contains a fault endIndex(str.endIndex, it should be its own endIndex, range.endIndex), which leads the issue.</span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">Zhaoxin</font></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 12:02 AM, Dmitri Gribenko <span dir="ltr">&lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, May 17, 2016 at 5:46 AM, zh ao via swift-users<br>
&lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
&gt; It seams that I encountered bugs in function advancedBy().<br>
&gt;<br>
</span><span class="">&gt; do {<br>
&gt;     var str = &quot;abcdefg&quot;<br>
&gt;     var range = str.startIndex..&lt;str.endIndex // 0..&lt;7<br>
&gt;     str += &quot;hijklmn&quot;<br>
&gt;     range.endIndex = str.endIndex // 0..&lt;14<br>
&gt;     let index = range.startIndex.advancedBy(10)<br>
&gt;     //fatal error: cannot increment endIndex<br>
&gt; }<br>
<br>
</span>Hi,<br>
<br>
Thank you for the report.  To me, this issue looks the same as<br>
<a href="https://bugs.swift.org/browse/SR-1487" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/SR-1487</a>.<br>
<span class="HOEnZb"><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>&gt;*/<br>
</font></span></blockquote></div><br></div>