Bug in valarray

Andreas Amann amann@physik.tu-berlin.de
Tue Oct 19 09:30:00 GMT 1999


Version: gcc-2.95.1, current CVS
System: Linux, etc.



Hi, 

I noticed that the valarray package distributed with the gcc-2.95.1,
is not synced with the version in libstdc++-2.90.6. 
Especially the file valarray_meta.h still (even in the recent CVS
tree) contains a bug, which, after I reported it to Gabriel Dos-Reis,
was fixed in the libstc++ already some time ago.  

I would like to ask the person responsible for the valarray package at
gcc, to sync with Gabriel's latest version, or at least apply the
following patch
----------------
--- valarray_meta.h     Thu Jul 29 09:59:46 1999
+++ valarray_meta.h     Thu Jul 29 10:12:21 1999
@@ -449,7 +449,7 @@
     typedef _BinBase<_Oper,valarray<_Tp>,_Dom> _Base;
     typedef typename _Base::value_type value_type;
     
-    _BinClos (const valarray<_Tp> __e1, const _Dom& __e2)
+    _BinClos (const valarray<_Tp>& __e1, const _Dom& __e2)
             : _Base (__e1, __e2) {}
 };

----------------

otherwise the following
code segfaults:

----------------
#include <valarray>
#include <iostream>

int main()
{
    valarray<double> a(10), b(10), c(10), d(10);

    a = 1.2;
    b = 3.1;

    c = 4.0;

    d = ( 2.0 * b + a );  // works
    cout << "d[4] = " << d[4] << endl;

    d = (a * 2.0 + b ); // works 
    cout << "d[4] = " << d[4] << endl;

    d = (a + b * 2.0 ); // segfaults!
    cout << "d[4] = " << d[4] << endl;
    d = (a + 2.0* b );

    cout << "d[4] = " << d[4] << endl;
    d = (a + 2.0* b );

    cout << "d[4] = " << d[4] << endl;
}
--------------------
Output:
bill:[junk] >g++ test_valarray.cc -g -o test_valarray
bill:[junk] >test_valarray
d[4] = 7.4
d[4] = 5.5
Segmentation fault

--------------------


Best regards 

Andreas Amann





-- 
Andreas Amann
Institut für theoretische Physik
TU Berlin

Tel.: +49-30-314-27658


More information about the Gcc-bugs mailing list