Ticket #8438 (new Bugs)

Opened 3 years ago

Last modified 2 years ago

vector & circular_buffer storage misbehave when using compiler optimizations

Reported by: ofir Owned by: guwi17
Milestone: To Be Determined Component: uBLAS
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc: dgregor, jano_gaspar, ofirmebel@…

Description (last modified by viboes) (diff)

When compiling the following code without optimizations, it behaves as expected: (compiled with g++-4.7.2 with no flags at all)

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/circular_buffer.hpp>

int main () {
    boost::numeric::ublas::vector<double, boost::circular_buffer<double> > v (3, 1);
    std::cout << v << std::endl;
    v[1] = 5;
    std::cout << v << std::endl;
    std::cout << v[1] << std::endl;
    return 0;



When compiling the exact same code with O1, O2, and O3 it produces the following output:


I noticed that inner_prod() also sees the vector as zeros.


Change History

comment:1 Changed 3 years ago by ofir <ofirmebel@…>

  • Cc ofirmebel@… added

comment:2 Changed 3 years ago by marshall

I was able to replicate this with clang, but I got a warning which probably has some bearing here:

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<double,
      boost::circular_buffer<double, std::allocator<double> > >::operator()'
      requested here
            s << v () (0);
junk.cpp:7:15: note: in instantiation of function template specialization
      'boost::numeric::ublas::operator<<<char, std::char_traits<char>,
      boost::numeric::ublas::vector<double, boost::circular_buffer<double,
      std::allocator<double> > > >' requested here
    std::cout << v << std::endl;
1 warning generated.

comment:3 Changed 3 years ago by viboes

  • Description modified (diff)

comment:4 Changed 2 years ago by viboes

  • Owner changed from jano_gaspar to guwi17
  • Component changed from circular_buffer to uBLAS

Could some experts of UBlas take a look at this ticket? Please, reassign to circular buffer if this has nothing to be with UBlas.


Add a comment

Modify Ticket

Change Properties
<Author field>
as new

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.