[Boost-bugs] [Boost C++ Libraries] #6626: shallow_array_adaptor bug in swap function

Subject: [Boost-bugs] [Boost C++ Libraries] #6626: shallow_array_adaptor bug in swap function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-02-28 16:50:00


#6626: shallow_array_adaptor bug in swap function
------------------------------------------------------------+---------------
 Reporter: Guillermo Ruiz Troyano <ruiztroyano@…> | Owner: guwi17
     Type: Bugs | Status: new
Milestone: Boost 1.50.0 | Component: uBLAS
  Version: Boost 1.49.0 | Severity: Problem
 Keywords: boost::numeric::ublas::shallow_array_adaptor |
------------------------------------------------------------+---------------
 ''boost::numeric::ublas::vector< T,shallow_array_adaptor<T> >'' fails when
 it is assigned with an expression. For example:

 {{{
 #define BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR
 #include <boost/numeric/ublas/vector.hpp>

 struct point {
    double x;
    double y;
    double z;
 };

 void test() {
    using namespace boost::numeric::ublas;

    point p = { 1, 2, 3 }
    shallow_array_adaptor<double> a(3, &p.x); // Ok, a holds p
 address
    vector<double, shallow_array_adaptor<double> > v(a); // Ok, v holds p
 address

    v += v; // Ok, now p = { 2, 4, 6 }
    v /= 2; // Ok, now p = { 1, 2, 3 }
    v = v*2; // <- Oh no, p = { 1, 2, 3 } !!!
 }
 }}}

 ''vector'' creates a temporary object and it calls to
 ''shallow_array_adaptor::swap''. This function doesn't check if it is the
 owner of pointers to swap. When both are data owners can do that (as
 unbounded_array does). But if they are not then they should swap as
 bounded_array does.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6626>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC