Problems with slices and valarrays (2nd)

Marc-Oliver Gewaltig Marc-Oliver.GewaltigAThre-ftr.f.rd.honda.co.jp
Fri Sep 17 04:34:00 GMT 1999


Hi,

in my previous post, I did send a code example, whose behaviour 
is undefined according to the ISO standard.

The following corrected example shows the same error.

----

#include <iostream>
#include <cassert>
#include <valarray>

  
int main(void)
{
  int alpha[] = {1,2,3,4,5,6,7,8,9,0};

  valarray<int> v(alpha,10);
  slice s(0,5,2);
  valarray<int> v2(v[s]);

  assert(v2.size() == 5);
  

  for(int i=0; i< v2.size(); ++i)
    cout << v2[i] << endl;

  assert(v2[0] == v[0]);

  return 0;
}

----

It should print

1
3
5
7
9

The output on Sparc Solaris 2.6 is

tiger:/home/gewaltig/source/c++>./valartst
225393
3
5
7
9
valartst.cc:20: failed assertion `v2[0] == v[0]'
Abort

the example was compiled with

g++ -v valartst.cc -o valartst
Reading specs from
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/specs
gcc version 2.95.1 19990816 (release)
 /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/cpp -lang-c++ -v
-D__GNUC__=2
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix
-D__svr4__ -
D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc
-D__sun -
D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS
-D__GCC_NEW_VARARGS__ -Acpu
(sparc) -Amachine(sparc) valartst.cc /var/tmp/cc0OqrGh.ii
GNU CPP version 2.95.1 19990816 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:

/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/../../../../include/g++-3
 /usr/local/include

/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/../../../../sparc-sun-solaris2
.6/include
 /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/include
 /usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
 /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/cc1plus
/var/tmp/cc0OqrGh.ii -
quiet -dumpbase valartst.cc -version -o /var/tmp/ccjvgOKK.s
GNU C++ version 2.95.1 19990816 (release) (sparc-sun-solaris2.6)
compiled by GNU
 C version 2.95.1 19990816 (release).
 /opt/gnu/sparc-sun-solaris2.6/bin/as -V -Qy -s -o /var/tmp/ccH10T1Q.o
/var/tmp/
ccjvgOKK.s
GNU assembler version 2.9.1 (sparc-sun-solaris2.6), using BFD version
2.9.1
 /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/collect2 -V -Y
P,/usr/ccs/lib:
/usr/lib -Qy -o valartst
/opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/crt1.o
 /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/crti.o
/usr/ccs/lib/values-Xa.
o /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/crtbegin.o
-L/opt/gnu/lib/gcc
-lib/sparc-sun-solaris2.6/2.95.1 -L/opt/gnu/sparc-sun-solaris2.6/lib
-L/usr/ccs/
bin -L/usr/ccs/lib -L/opt/gnu/lib /var/tmp/ccH10T1Q.o -lstdc++ -lm -lgcc
-lc -lg
cc /opt/gnu/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/crtend.o
/opt/gnu/lib/gcc-li
b/sparc-sun-solaris2.6/2.95.1/crtn.o
GNU ld version 2.9.1 (with BFD 2.9.1)    
  Supported emulations:
   elf32_sparc     

--- 


-- 

------------------------
Marc-Oliver Gewaltig (Dipl. Phys.)
Future Technology Research      Tel. +49-(0)69-89011-739
HONDA R&D Europe GmbH           Fax. +49-(0)69-89011-749
Carl-Legien-Str. 30
D-63073 Offenbach/Main
e-mail.    Marc-Oliver.Gewaltig@hre-ftr.f.rd.honda.co.jp


More information about the Gcc-bugs mailing list