This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11179] New: valarray resize error


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11179

           Summary: valarray resize error
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mmckerns@caltech.edu
                CC: gcc-bugs@gcc.gnu.org

I believe there is an error in the valarray.resize source.
The behavior is different that resize for other C++ containers,
such as vector.
Using vector in the included code sample yields:
0
1
2
0
1
2
3
0
1
2

for valarray,
  void resize(size_t _Newsize);                       sets all elements == 0
  void resize(size_t _Newsize, const Type& _Val);     sets all elements == _Val

CODE SAMPLE:
/* test.cpp */
#include <iostream>
#include <valarray>
using namespace std:
main() {
        valarray<double> val(3);
        for(int i=0; i<val.size(); i++) {
                val[i] = i;
                cout<<"val["<<i<<"] = "<<val[i]<<endl;
        }
        val.resize(4,3.0);
        for(int i=0; i<val.size(); i++) {
                cout<<"val["<<i<<"] = "<<val[i]<<endl;
        }
        val.resize(3);
        for(int i=0; i<val.size(); i++) {
                cout<<"val["<<i<<"] = "<<val[i]<<endl;
        }
}

SAMPLE COMPILE:
mmckerns>$ make
g++ -ftemplate-depth-30 -g -DBZ_DEBUG -c test.cpp
g++  test.o -o test -lstdc++

SAMPLE OUTPUT:
mmckerns>$ ./test
val[0] = 0
val[1] = 1
val[2] = 2
val[0] = 3
val[1] = 3
val[2] = 3
val[3] = 3
val[0] = 0
val[1] = 0
val[2] = 0


COMPILE ERRORS:
none!!!

SYSTEM INFO:
mmckerns>$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]