SAITO@sdr.slb.com ("Naoki Saito Ext. 5471", GEO-002) (01/09/89)
Dear FSF people; I observed the bug of the g++ 1.27.0 as follows: o When I compiled the following program, I got the fatal signal like this: $ g++ -g -O -fchar-charconst -o vector vector.cc -lm -v g++ version 1.27.0 /usr/local/lib/gcc-cpp+ -v -undef -D__GNU__ -D__GNUG__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ vector.cc /tmp/cca23630.cpp GNU CPP version 1.27.0 /usr/local/lib/gcc-c++ /tmp/cca23630.cpp -quiet -dumpbase vector.cc -fchar-charconst -opt -version -G -o /tmp/cca23630.s GNU C++ version 1.27.0 (68k, MIT syntax) compiled by GNU C version 1.27. Failed assertion (0) at line 1569 of `search.c'. g++: Program c++ got fatal signal 6. o My machine is Sun 3/60 running Sun OS 3.4. And tm.h -> tm-sun3+.h and md -> ../gcc/m68k.md. o The following is the input files. The problem occurs when some member functions of the class has accidentally the same name as the member variable of its derived class. Here, function at() is declared in class vector and int at is also declared by in the derived class vec. This kind of accident may occur when classes gets bigger and should be warned by the complier. Regards, Naoki Saito (saito@sdr.slb.com) Schlumberger-Doll Research =============================================================================== // file vector.h #include <stream.h> class vector { int* v; int sz; vector(int, int*); public: vector(int); ~vector(); int size(); int& operator[](int); int& elem(int); vector at(int from = 0, int to = -1); }; inline vector::vector(int n) { if (n <= 0) exit(1); else { sz = n; v = new int[n]; } } inline vector::vector(int n, int* buf) { sz = n; v = buf; } inline vector::~vector() { delete v; } inline int vector::size() { return sz; } inline int& vector::operator[](int i) { if (i < 0 || sz <= i) exit(1); else return v[i]; } inline int& vector::elem(int i) { return v[i]; } class vec : public vector { int low, high; public: vec(int, int); int& elem(int); int& operator[](int); int at; }; inline vec::vec(int m, int n) : (n - m + 1) { if (n < m) { int tmp = m; m = n; n = tmp; } low = m; high = n; } inline int& vec::operator[](int i) { if (i < low || high < i) exit(1); else return elem(i); } inline int& vec::elem(int i) { return vector::elem(i-low); } =============================================================================== // file vector.cc: main program. #include "vector.h" main() { vector a(10); for (int i = 0; i < a.size(); i++) { a[i] = i; cout << a[i] << " "; } cout << "\n"; vec b(10, 19); for (i = 0; i < b.size(); i++) b[i+10] = a[i]; for (i = 0; i < b.size(); i++) cout << b[i+10] << " "; cout << "\n"; }