schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (09/22/88)
Hi,
The following erroneous code produces a fatal signal on Sun Sparc.
----------------------------------------
static const int Default_Range = 100;
static const int Default_Size = 100;
class Ullman_Array {
private:
int Default_Value;
int Max_Range;
int Max_Size;
int *Index_Array;
int *Hand_Shake_Array;
int *Storage_Array;
int Current_Max;
public:
Ullman_Array(int Array_Range, int Set_Size = 0,) { // here's problem 1
if (Set_Size == 0) {
Set_Size = Array_Range;
}
Max_Range = Array_Range;
Max_Size = Set_Size;
Index_Array = new int[Max_Range];
Hand_Shake_Array = new int[Max_Size];
Storage_Array = new int[Max_Size];
Current_Max = -1;
}
Ullman_Array(int Array_Range, int Fill, int Set_Size = 0,) {
if (Set_Size == 0) {
Set_Size = Array_Range;
}
Default_Value = Fill;
Max_Range = Array_Range;
Max_Size = Set_Size;
Index_Array = new int[Max_Range];
Hand_Shake_Array = new int[Max_Size];
Storage_Array = new int[Max_Size];
Current_Max = -1;
}
int& operator[](int Index) {
int Hand_Shake_Index = Index_Array[Index];
if ((Hand_Shake_Index < 0) || (Hand_Shake_Index > Current_Max) ||
(Index != Hand_Shake_Array[Hand_Shake_Index])) {
Hand_Shake_Index = ++Current_Max;
Hand_Shake_Array[Hand_Shake_Index] = Index;
Index_Array[Index] = Hand_Shake_Index;
Storage_Array[Hand_Shake_Index] = Default_Value;
}
return(Storage_Array[Hand_Shake_Index]);
}
int Total_Range(void) {
return (Max_Range);
}
int Total_Size(void) {
return(Max_Size);
}
int Current_Size(void) {
return(Current_Max);
}
};
main(int argc,char *argv[]) {
int i = atoi(argv[1]);
int n = i;
Ullman_Array A(n);
while (--i) {
A[i] = rand();
}
i = n;
while (--i) {
cout << A[i] << "\n";
}
}
----------------------------------------
and here's the diagnostic:
----------------------------------------
g++ version 1.27.0
/usr/public/lib/g++/gcc-cpp+ -v -I/cl/ua/schmidt/include/ -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix bug.cc /tmp/cca19709.cpp
GNU CPP version 1.27.0
/usr/public/lib/g++/gcc-c++ /tmp/cca19709.cpp -quiet -dumpbase bug.cc -fmemoize-lookups -fsave-memoized -fchar-charconst -noreg -version -o /tmp/cca19709.s
bug.cc:17: warning: type specifier omitted for parameter
bug.cc:17: all trailing parameters must have default arguments
bug.cc:29: warning: type specifier omitted for parameter
bug.cc:29: all trailing parameters must have default arguments
bug.cc:72: Segmentation violation
/usr/public/g++: Program c++ got fatal signal 11.schmidt%siam.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (10/01/88)
Hi,
The following program gets a fatal signal when compiled with g++
1.27 running on the sparc. I've indicated the problem with a comment
in the code below.
Here's the code:
----------------------------------------
# 1 "bug.cc"
# 1 "/usr/public/lib/g++/g++-include/setjmp.h"
static const int _JBLEN = 15;
typedef int jmp_buf[_JBLEN];
extern int setjmp(jmp_buf);
extern void longjmp(jmp_buf, int);
# 1 "bug.cc"
const int TRIVIAL_ERROR = 1;
class cleanup_obj {
friend class error_handler;
static cleanup_obj* cleanup_obj_head;
cleanup_obj *prev;
cleanup_obj *next;
protected:
cleanup_obj(): prev(0),next(cleanup_obj_head) {
if (next) {
next->prev = this;
}
cleanup_obj_head = this;
}
~cleanup_obj() {
cleanup();
}
virtual void cleanup() {
if (prev) {
prev->next = next;
}
else {
cleanup_obj_head = next;
}
if (next) {
next->prev = prev;
}
}
};
typedef int error_function(int err_num,class error_handler *ehp);
class error_handler : public cleanup_obj {
friend void report_error(int err_num);
static error_handler *top_of_stack;
error_handler *next;
error_function *func;
public:
jmp_buf abort_label;
error_handler(error_function err_func = 0):
// change error_function to error_function * and problem goes away!
next(top_of_stack), func(err_func) {
top_of_stack = this;
}
void cleanup() {
top_of_stack = next;
cleanup_obj::cleanup();
}
void abort(int ret_val) {
while ((cleanup_obj::cleanup_obj_head) &&
(cleanup_obj::cleanup_obj_head != this)) {
cleanup_obj::cleanup_obj_head->cleanup();
}
longjmp(abort_label,ret_val);
}
void operator=(error_function *err_func) {
func = err_func;
}
};
----------------------------------------
Here's the diagnostic:
----------------------------------------
g++ version 1.27.0
/usr/public/lib/g++/gcc-cpp+ -v -I/cd/ua/schmidt/include/ -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix bug.cc /tmp/cca00426.cpp
GNU CPP version 1.27.0
/usr/public/lib/g++/gcc-c++ /tmp/cca00426.cpp -quiet -dumpbase bug.cc -fchar-charconst -noreg -version -o /tmp/cca00426.s
GNU C++ version 1.27.0 (sparc) compiled by GNU C version 1.28.
/usr/public/g++: Program c++ got fatal signal 6.schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (10/04/88)
Howdy,
The following short program kills 1.27 running on Sparc.
----------------------------------------
class String {
public:
String(char *S) {
;
}
friend String& operator &(String& S1,char *S2) {
;
}
};
main() {
String Foo = "A";
String Foobar = Foo & "B";
}
----------------------------------------
g++ version 1.27.0
echo use .cc filename extension!
use .cc filename extension!
/usr/public/lib/g++/gcc-cpp+ -v -I/cd/ua/schmidt/include/ -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix test.C /tmp/cca19086.cpp
GNU CPP version 1.27.0
/usr/public/lib/g++/gcc-c++ /tmp/cca19086.cpp -quiet -dumpbase test.C -fchar-charconst -noreg -version -o /tmp/cca19086.s
GNU C++ version 1.27.0 (sparc) compiled by GNU C version 1.28.
/usr/public/g++: Program c++ got fatal signal 6.