Boost C++ Libraries: Ticket #5352: BOOST_REVERSE_FOREACH does not work with boost::counting_iterator (gcc 4.5.0 and 4.5.2 using -O3) https://svn.boost.org/trac10/ticket/5352 <p> The following code: </p> <pre class="wiki">#include &lt;iostream&gt; #include "boost/foreach.hpp" #include &lt;boost/iterator/counting_iterator.hpp&gt; int main(int, char**) { boost::counting_iterator&lt;int&gt; start(0), end(10); std::pair&lt;boost::counting_iterator&lt;int&gt;, boost::counting_iterator&lt;int&gt; &gt; iterators(start, end); std::cout &lt;&lt; "Counting: "; BOOST_REVERSE_FOREACH(int t, iterators) { std::cout &lt;&lt;t&lt;&lt;" "; } std::cout &lt;&lt; std::endl; } </pre><p> works fine with gcc-4.4.5 using -O3: </p> <pre class="wiki">Counting: 9 8 7 6 5 4 3 2 1 0 </pre><p> but fails for gcc-4.5.0 and gcc-4.5.2 using -O3: </p> <pre class="wiki">Counting: 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 70263556 </pre><p> System: i686-pc-linux-gnu </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5352 Trac 1.4.3 mimomorin@… Tue, 22 Mar 2011 10:41:05 GMT <link>https://svn.boost.org/trac10/ticket/5352#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5352#comment:1</guid> <description> <p> This is a limitation of <code>counting_iterator</code> and not a bug of Boost.Foreach. See <a class="new ticket" href="https://svn.boost.org/trac10/ticket/2640" title="#2640: Bugs: Legal forward iterators cannot store their referents (was: ... (new)">#2640</a>. </p> </description> <category>Ticket</category> </item> <item> <author>Marc-Peter Schambach <Marc-Peter.Schambach@…></author> <pubDate>Tue, 22 Mar 2011 16:52:08 GMT</pubDate> <title>owner, component changed https://svn.boost.org/trac10/ticket/5352#comment:2 https://svn.boost.org/trac10/ticket/5352#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Eric Niebler</span> to <span class="trac-author">Dave Abrahams</span> </li> <li><strong>component</strong> <span class="trac-field-old">foreach</span> → <span class="trac-field-new">iterator</span> </li> </ul> Ticket Michel Morin <mimomorin@…> Wed, 07 Sep 2011 23:04:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5352#comment:3 https://svn.boost.org/trac10/ticket/5352#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Duplicate of <a class="new ticket" href="https://svn.boost.org/trac10/ticket/2640" title="#2640: Bugs: Legal forward iterators cannot store their referents (was: ... (new)">#2640</a>. </p> Ticket