[gnu.g++.bug] bug in sparc g++ 1.34.1

trq@MOOSE.CITA.UTORONTO.CA (Tom Quinn) (03/21/89)

G++ will get a segmentation violation when compiling the following
code with the "-O" option.  This is g++ version 1.34.1 on a Sun4/110
running SunOs 4.0.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.utoronto.ca
UUCP   - decvax!utgpu!moose!trq
BITNET - quinn@utorphys.bitnet
ARPA   - trq%moose.cita.toronto.edu@relay.cs.net

The compile:
g++ -g -v -O   -c snapcc.cc -o snapcc.o
g++ version 1.34.1
 /usr/local/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ snapcc.cc /tmp/cca18859.cpp
GNU CPP version 1.34
 /usr/local/lib/gcc-c++ /tmp/cca18859.cpp -quiet -dumpbase snapcc.cc -opt -version -G -o /tmp/cca18859.s
GNU C++ version 1.34.1 (sparc) compiled by GNU C version 1.34.
In method void ParticleVec::apply (auto void (*)(struct ParticleRec )):
snapcc.cc:26: Segmentation violation
Program c++ got fatal signal 11.

The code:
------------------------------------------------------------------------
struct ParticleRec {
	double x, y, z, vx, vy, vz;
};
typedef struct ParticleRec Particle;
typedef void (*ParticleProcedure)(Particle );
class ParticleVec 
{
protected:
  int                   len;
  Particle                   *s;                  
                        ParticleVec(int l, Particle* d);
public:
                        ParticleVec ();
                        ParticleVec (int l);
                        ParticleVec (int l, Particle  fill_value);
                        ParticleVec (ParticleVec&);
                        ~ParticleVec ();
  ParticleVec &              operator = (ParticleVec & a);
  Particle&                  operator [] (int n);
  void                  apply(ParticleProcedure f);
};
inline void ParticleVec::apply(ParticleProcedure f)
{
  Particle* top = &(s[len]);
  Particle* t = s;
  while (t < top) (*f)(*t++);
}