|
Ublas : |
Subject: [ublas] Assignment bug with MSVC
From: Hartley, Bob (Bob.Hartley_at_[hidden])
Date: 2011-06-23 17:07:44
GentleBoosters --
I have recently been forced to upgrade to MSVC 2010, and have found that
some assignments that have always worked, no longer do. The simplest
example that I come up with is this:
BOOST_AUTO_TEST_CASE(test_null_pointer)
{
boost::numeric::ublas::matrix<double> A;
boost::numeric::ublas::matrix<double> B;
B.resize(0,0,false);
A = B;
}
In MSVC 7.1/GCC 3.4.4, this runs fine and without a hitch (e.g.):
rhartley> ./UnitTests/unit_tests_dbg.exe --build_info
--run_test='test_null_pointer'
Running 1 test case...
Platform: Cygwin
Compiler: GNU C++ version 3.4.4 (cygming special, gdc 0.12, using dmd
0.125)
STL : GNU libstdc++ version 20050519
Boost : 1.44.0
However, in MSVC 10.0 (2010), this returns with the error:
*** No errors detected
rhartley> ./UCTF_MSVC/Debug/UnitTest_MSVC.exe --build_info
--run_test='test_null_pointer'
Running 1 test case...
Platform: Win32
Compiler: Microsoft Visual C++ version 10.0
STL : Dinkumware standard library version 520
Boost : 1.44.0
unknown location(0): fatal error in "test_null_pointer": c:\program
files\microsoft visual studio 10.0\vc\include\xutility(2225) : Assertion
failed: invalid null pointer
*** 1 failure detected in test suite "Master Test Suite"
This seems to stem from a Debug assertion now in MSVC's implementation
of std::copy that complains that the destination is NULL, and breaks the
program there. This is fixed by checking that the size of the std::copy
is greater than zero in storage.hpp (199) as in here:
// Assignment
BOOST_UBLAS_INLINE
unbounded_array &operator = (const unbounded_array &a) {
if (this != &a) {
resize (a.size_);
#ifdef BOB_MSVC10_COPY_WORKAROUND
if (a.size_ > 0 )
#endif BOB_MSVC10_COPY_WORKAROUND
std::copy (a.data_, a.data_ + a.size_, data_);
}
return *this;
}
I think this is horrible and inelegant; how _should_ this have been
fixed?
Bob