Opened 10 years ago
Last modified 9 years ago
#8438 new Bugs
vector & circular_buffer storage misbehave when using compiler optimizations
| Reported by: | ofir | Owned by: | Gunter |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | uBLAS |
| Version: | Boost 1.52.0 | Severity: | Problem |
| Keywords: | Cc: | Douglas Gregor, Jan Gaspar, ofirmebel@… |
Description (last modified by )
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;
}
Output:
[3](1,1,1) [3](1,5,1) 5
When compiling the exact same code with O1, O2, and O3 it produces the following output:
[3](0,0,0) [3](0,0,0) 5
I noticed that inner_prod() also sees the vector as zeros.
Change History (4)
comment:1 by , 10 years ago
| Cc: | added |
|---|
comment:2 by , 10 years ago
comment:3 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:4 by , 9 years ago
| Component: | circular_buffer → uBLAS |
|---|---|
| Owner: | changed from to |
Could some experts of UBlas take a look at this ticket? Please, reassign to circular buffer if this has nothing to be with UBlas.
Note:
See TracTickets
for help on using tickets.

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.