Boost C++ Libraries: Ticket #8438: vector & circular_buffer storage misbehave when using compiler optimizations https://svn.boost.org/trac10/ticket/8438 <p> When compiling the following code without optimizations, it behaves as expected: (compiled with g++-4.7.2 with no flags at all) </p> <pre class="wiki">#include &lt;boost/numeric/ublas/vector.hpp&gt; #include &lt;boost/numeric/ublas/io.hpp&gt; #include &lt;boost/circular_buffer.hpp&gt; int main () { boost::numeric::ublas::vector&lt;double, boost::circular_buffer&lt;double&gt; &gt; v (3, 1); std::cout &lt;&lt; v &lt;&lt; std::endl; v[1] = 5; std::cout &lt;&lt; v &lt;&lt; std::endl; std::cout &lt;&lt; v[1] &lt;&lt; std::endl; return 0; } </pre><p> Output: </p> <pre class="wiki">[3](1,1,1) [3](1,5,1) 5 </pre><p> When compiling the exact same code with O1, O2, and O3 it produces the following output: </p> <pre class="wiki">[3](0,0,0) [3](0,0,0) 5 </pre><p> I noticed that inner_prod() also sees the vector as zeros. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8438 Trac 1.4.3 ofir <ofirmebel@…> Mon, 15 Apr 2013 12:38:00 GMT cc changed https://svn.boost.org/trac10/ticket/8438#comment:1 https://svn.boost.org/trac10/ticket/8438#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">ofirmebel@…</span> added </li> </ul> Ticket Marshall Clow Mon, 15 Apr 2013 19:08:24 GMT <link>https://svn.boost.org/trac10/ticket/8438#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8438#comment:2</guid> <description> <p> I was able to replicate this with clang, but I got a warning which probably has some bearing here: </p> <pre class="wiki">trunk/boost/numeric/ublas/vector.hpp:205:20: warning: returning reference to local temporary object [-Wreturn-stack-address] return data () [i]; ^~~~~~~~~~~ trunk/boost/numeric/ublas/io.hpp:58:18: note: in instantiation of member function 'boost::numeric::ublas::vector&lt;double, boost::circular_buffer&lt;double, std::allocator&lt;double&gt; &gt; &gt;::operator()' requested here s &lt;&lt; v () (0); ^ junk.cpp:7:15: note: in instantiation of function template specialization 'boost::numeric::ublas::operator&lt;&lt;&lt;char, std::char_traits&lt;char&gt;, boost::numeric::ublas::vector&lt;double, boost::circular_buffer&lt;double, std::allocator&lt;double&gt; &gt; &gt; &gt;' requested here std::cout &lt;&lt; v &lt;&lt; std::endl; ^ 1 warning generated. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 21 May 2013 18:49:41 GMT</pubDate> <title>description changed https://svn.boost.org/trac10/ticket/8438#comment:3 https://svn.boost.org/trac10/ticket/8438#comment:3 <ul> <li><strong>description</strong> modified (<a href="/trac10/ticket/8438?action=diff&amp;version=3">diff</a>) </li> </ul> Ticket viboes Sun, 09 Jun 2013 21:05:23 GMT owner, component changed https://svn.boost.org/trac10/ticket/8438#comment:4 https://svn.boost.org/trac10/ticket/8438#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Jan Gaspar</span> to <span class="trac-author">Gunter</span> </li> <li><strong>component</strong> <span class="trac-field-old">circular_buffer</span> → <span class="trac-field-new">uBLAS</span> </li> </ul> <p> Could some experts of UBlas take a look at this ticket? Please, reassign to circular buffer if this has nothing to be with UBlas. </p> Ticket