Article View: gnu.g++.bug
Article #804gcc 2.2.2 C++ fatal error
From: bilmes
Date: Fri, 14 Aug 1992 12:19
Date: Fri, 14 Aug 1992 12:19
125 lines
3966 bytes
3966 bytes
The following C++ program, not correct or debugged, produces a fatal
error in gcc v 2.2.2. The behavior is the same on SPARC machines.
gcc -v -o Array{,.cc} -DMAIN
Reading specs from /usr/local/lib/gcc-lib/mips-dec-ultrix4.2/2.2.2/specs
gcc version 2.2.2
/usr/local/lib/gcc-lib/mips-dec-ultrix4.2/2.2.2/cpp -lang-c++ -v -DMAIN -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__ANSI_COMPAT -DMIPSEL -DR3000 -DSYSTYPE_BSD -D_SYSTYPE_BSD -Dbsd4_2 -Dhost_mips -Dmips -Dultrix -Dunix -D__ANSI_COMPAT -D__MIPSEL__ -D__R3000__ -D__SYSTYPE_BSD__ -D___SYSTYPE_BSD__ -D__bsd4_2__ -D__host_mips__ -D__mips__ -D__ultrix__ -D__unix__ -D__ANSI_COMPAT -D__MIPSEL -D__R3000 -D__SYSTYPE_BSD -D___SYSTYPE_BSD -D__bsd4_2 -D__host_mips -D__mips -D__ultrix -D__unix -I/usr/local/lib/gc
c-lib/mips-dec-ultrix4.2/2.2.2/lib/g++-include -D__LANGUAGE_C_PLUS_PLUS__ -D__LANGUAGE_C_PLUS_PLUS -D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C Array.cc /usr/tmp/cca21136.i
GNU CPP version 2.2.2 [AL 1.1, MM 19] DECstation running ultrix
/usr/local/lib/gcc-lib/mips-dec-ultrix4.2/2.2.2/cc1plus /usr/tmp/cca21136.i -quiet -dumpbase Array.cc -version -o /usr/tmp/cca21136.s
GNU C++ version 2.2.2 [AL 1.1, MM 19] DECstation running ultrix compiled by GNU C version 2.2.2.
gcc: Internal compiler error: program cc1plus got fatal signal 11
----------------------- Array.h -----------------------------------------------
/*
** Array of T
*/
#include <iostream.h>
#include <fstream.h>
#include <std.h>
template <class T>
class Array {
protected:
T *data;
int arrayLength;
public:
Array(int size=0);
Array(int size,T *);
~shortArray();
T& operator[](int n) { return data[n]; }
T* dataLoc(int n=0) { return &data[n]; }
int length() { return arrayLength; }
friend istream& operator>>(istream&,Array<T>&);
friend ostream& operator<<(ostream&,Array<T>&);
};
------------------- Array.cc ----------------------------------------------
#include <std.h>
#include "Array.h"
template <class T>
Array<T>::Array(int size) {
if (size == 0)
data = NULL;
else {
data = new T[size];
if (data == NULL) {
cerr << "Can't new " << size << " items in array.\n";
::exit(1);
}
}
arrayLength = size;
}
template <class T>
Array<T>::Array(int size,T *d) {
data = d;
arrayLength = size;
}
template <class T>
Array<T>::~Array() {
if (data != NULL)
delete data;
}
template <class T>
istream& operator>>(istream&s,Array<T> &a) {
if (a.data != NULL)
delete a.data;
a.data = new T[16];
a.arrayLength = 0;
int datasize = 16;
T t;
while (s >> t) {
a.data[a.arrayLength++] = t;
if (a.arrayLength >= datasize) {
int newlen = datasize*2;
T* olddata = a.data;
a.data = new T[newlen];
::bcopy(olddata,a.data,datasize*sizeof(T));
delete olddata;
datasize = newlen;
}
}
if (a.arrayLengh > 0) {
T* olddata = a.data;
a.data = new T[a.arrayLength];
::bcopy(olddata,a.data,a.arrayLength*sizeof(T));
delete olddata;
}
}
template <class T>
ostream& operator<<(ostream&s,Array<T> &a) {
for (int i=0;i<a.length();i++)
s << a[i];
return s;
}
#ifdef MAIN
main(int argc,char*argv[]) {
if (argc < 2) {
cout << "need filename\n";
::exit(1);
}
ifstream is(argv[1]);
Array<float> af;
is >> af;
cout << af;
}
#endif
-----------------------------------------------------------------
Technical Details
Message-ID:
<9208142019.AA21146@dufay.media.mit.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!media.mit.edu!bilmesShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!media.mit.edu!bilmes From: bilmes@media.mit.edu Subject: gcc 2.2.2 C++ fatal error Message-ID: <9208142019.AA21146@dufay.media.mit.edu> Sender: gnulists@ai.mit.edu Reply-To: Jeff Bilmes <bilmes@media-lab.media.mit.edu> (617/253-8163) Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 14 Aug 1992 12:19:40 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 135