Boost logo

Ublas :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-09-22 03:28:12


Michael Stevens wrote:

> Hi Angus.
>
> On Mittwoch 21 September 2005 12:51, Angus Leeming wrote:
>> The following simple little code produces a warning with current Boost
>> cvs.
>>
>> $ g++ --version
>> g++ (GCC) 4.0.2 20050917 (prerelease) (Debian 4.0.1-8)
>>
>> $ g++ -I/home/aleem/boost/cvs -DNDEBUG -O2 -W -Wall -c test.C
>> /home/aleem/boost/cvs/boost/numeric/ublas/storage.hpp: In function
>> 'void make_weights(const Vector&, double, double)':
>> /home/aleem/boost/cvs/boost/numeric/ublas/storage.hpp:123: warning:
>> 'data' may be used uninitialized in this function
>
> Angus. I cannot reproduce. Are you sure you have the most recent CVS
> HEAD. "storage.hpp" should be 1.67. This already has a change to avoid
> this warning.

Well, it doesn't here. This is Boost CVS, right? Not UBLAS CVS, if it still
exists.

$ grep storage.hpp boost/numeric/ublas/CVS/Entries
/storage.hpp/1.67/Mon Sep 12 19:18:12 2005//

$ cat -n storage.hpp
   120 BOOST_UBLAS_INLINE
   121 void resize_internal (size_type size, value_type init, bool
pres
erve) {
   122 if (size != size_) {
   123 pointer data;
   124 if (size) {
   125 data = alloc_.allocate (size);
   126 if (preserve) {

It's line 123 that I think needs changing. Compiling only the program below
with gcc 4.0.2 gives the warning. No warning is output with gcc 3.4.4.

>> #include <boost/numeric/ublas/vector.hpp>
>> typedef boost::numeric::ublas::vector<double> Vector;
>>
>> Vector const jacobi(Vector const & z, int n, double alpha, double
>> beta);
>>
>> void make_weights(Vector const & zeros, double const alpha, double
>> const beta)
>> {
>> Vector::size_type const P = zeros.size();
>> Vector weights(P);
>>
>> weights = jacobi(zeros, P-1, alpha, beta);
>> }

> I think the warning must come from a call to vector 'resize' member in
> 'jacobi'. Or am I missing something?

I'm compiling the test program above to illustrate the problem; there's no
implementation of jacobi at all. The resize occurs because the vector size
is specified in the "weights(P)" constructor call and then this size is,
possibly, changed in the "weights = jacobi(..." assignment.

Angus