Path: utzoo!telly!ddsw1!lll-winken!killer!osu-cis!tut.cis.ohio-state.edu!ORION.CF.UCI.EDU!schmidt%crimee.ics.uci.edu
From: schmidt%crimee.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: G++ 1.27 gets fatal signal on sparc
Message-ID: <8809220007.aa22332@PARIS.ICS.UCI.EDU>
Date: 22 Sep 88 07:07:15 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 102


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.