Boost C++ Libraries: Ticket #10430: joined_range generates invalid range with recent gcc versions with optimization enabled https://svn.boost.org/trac10/ticket/10430 <p> This came up in tracking down unit-test failures when trying to build a project with newer compiler versions with C++11 enabled. The unit-test in question was compiled with multiple compiler versions: </p> <ul><li>gcc 4.3.4 (without C++11 enabled): working at all optimization levels </li><li>gcc 4.7.2 (with C++11 enabled): works without optimizations, failed with -O1 or higher </li><li>gcc 4.8.4 (with C++11 enabled): works without optimizations, failed with -O1 or higher </li><li>clang 3.5.0 (recent build, with C++11 enabled): works at all optimization levels </li></ul><p> The failure was tracked down to a use of boost::range::joined_range (Boost 1.55.0), effectively declared as: </p> <pre class="wiki">boost::range::joined_range&lt;boost::iterator_range&lt;std::vector&lt;char&gt;::iterator, boost::iterator_range&lt;const char*&gt;&gt; </pre><p> In this form, the joined_range created from two valid ranges winds up "somewhere else" when the higher optimization level. I've attached a test case that demonstrates the problem. Compiled with: </p> <pre class="wiki">g++ -std=c++11 -o join_bug join_bug.cpp </pre><p> works (printing out the expected ASCII values of the joined ranges). Compiled with: </p> <pre class="wiki">g++ -O1 -std=c++11 -o join_bug join_bug.cpp </pre><p> fails (printing out zero's in my test, though the correct number of them). This test was run with the same compiler versions as above, on both Boost 1.54.0 and Boost 1.55.0, as well as gcc 4.8.2 and clang 3.4 (both for Ubuntu 14.04), with a slightly modified non-C++11 version for the gcc 4.3.4 compiler, all with the same successes/failures. </p> <p> The problem goes away in all tests if the joined_range is declared like so (changing from std::vector&lt;char&gt;::iterator to std::vector&lt;char&gt;::const_iterator): </p> <pre class="wiki">boost::range::joined_range&lt;boost::iterator_range&lt;std::vector&lt;char&gt;::const_iterator, boost::iterator_range&lt;const char*&gt;&gt; </pre><p> I realize this might be a gcc bug, rather than a Boost bug, but I haven't seen this reported elsewhere and would like to get the behaviour tracked since I'm only seeing problems in relation to joined_range... </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10430 Trac 1.4.3 Oliver Seiler <oseiler@…> Sat, 30 Aug 2014 19:41:15 GMT attachment set https://svn.boost.org/trac10/ticket/10430 https://svn.boost.org/trac10/ticket/10430 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">join_bug.cpp</span> </li> </ul> Ticket Neil Groves Mon, 01 Sep 2014 11:54:18 GMT status changed https://svn.boost.org/trac10/ticket/10430#comment:1 https://svn.boost.org/trac10/ticket/10430#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket