[gnu.g++.bug] g++-1.36.3 segv

vaughan%cadillac.cad.mcc.com@MCC.COM (Paul Vaughan) (01/17/90)

The following source, involving a virtual base class and virtual
methods, causes the compiler to segv.  This may be related to Newton's
previous bug report involving a similar hierarchy where the compiler
terminated successfully, but incorrect results were obtained.

#include <stream.h>
class NameSpaceTable;

class Object {
public:
  Object() {};
  virtual ~Object() {cout << "~Object()\n";}
  virtual int isA() { return 1; }
};

class NamedObject: public Object
{
public:
  NamedObject(const char* n = 0);
  ~NamedObject();

  virtual const char* Name() const;
  virtual int isA() { return 2; }
private:
  const char* name=0;
};

const char* NamedObject::Name() const {
  if (name) return name; else return "?????";
}

NamedObject::NamedObject(const char* n = 0): () {
  name = n;
  cout << (int) this << " NamedObject() Name() = " << Name() << "\n";
}

NamedObject::~NamedObject() {
  cout << (int) this << " ~NamedObject() " << (int)name << "\n";
}

class Entity: public  NamedObject {
public:
  Entity(const char* n=0,Entity* o=0,NameSpaceTable* nspace=0,
	 int namespaceSize = 100) : NamedObject(n) {};
  ~Entity() { cout << "~Entity()\n";}
  virtual int isA() { return 3; }
};

class Attribute : public virtual Entity {
public:
  Attribute(const char* n=0,Entity* o=0,NameSpaceTable* nspace=0) 
    : Entity(n,o,nspace,0) {};
  ~Attribute() {cout << "~Attribute()\n";}
  virtual int isA() { return 4; }
};

class IntegerAt : public Attribute {
public:
  IntegerAt(const char* n=0,Entity* o=0,NameSpaceTable* nspace=0)
    : Attribute(n,o,nspace) {};
//  ~IntegerAt() {cout << "~IntegerAt()\n";}
  virtual void SetValue(int) {};
  virtual int isA() { return 5; }
};

class Behavior : public virtual Entity {
public:
  Behavior(const char* n= 0, Entity* o = 0, NameSpaceTable* ns = 0, int s = 0) 
    : Entity (n, o, ns, s) {};  
  virtual ~Behavior() {cout << "~Behavior()\n";}
  virtual int isA() { return 6; }
};

class AttributeBehavior : public Behavior {
public:
  AttributeBehavior(const char* n = 0, Entity* o = 0, NameSpaceTable* ns = 0, 
		    int s = 0) : Behavior (n, o, ns, s) {}
  ~AttributeBehavior() {cout << "~AttributeBehavior()\n";}
  virtual int isA() { return 7; }
};

class InterAtt : public AttributeBehavior {
public:
  InterAtt()  {  cout << "InterAtt() Name() = " << Name() << "\n"; };
//  ~InterAtt() {cout << "~InterAtt()\n";}
  virtual int isA() { return 8; }
};

class ServiceDelayAt : public IntegerAt {
public:
  ServiceDelayAt() : IntegerAt("delay") {  
    cout << "ServiceDelayAt() Name() = " << Name() << "\n";
  };
//  virtual const char* Name() const { 
//    cout << "<" << (int) this << " ServiceDelayAt::Name>";
//    return NamedObject::Name(); }
  ~ServiceDelayAt() {};
  virtual int isA() { return 9; }
  virtual void SetValue(int) {};
};

class IServiceDelayAt : public InterAtt, public ServiceDelayAt {
public:
  IServiceDelayAt();
  ~IServiceDelayAt();
//  virtual const char* Name() const { 
//    cout << "<" << (int) this << " IServiceDelayAt::Name>";
//    return ServiceDelayAt::Name();
//  }
  virtual void SetValue(int) {};
  virtual int isA() { return 10; }
};

IServiceDelayAt::~IServiceDelayAt() {cout << "~ServiceDelayAt()\n";}

IServiceDelayAt::IServiceDelayAt() {  
  cout << "IServiceDelayAt()Name() = " << Name() << "\n";
}

main() {
  cout << "main()\n";
  cout.flush();
  IServiceDelayAt* delay = new IServiceDelayAt;
  cout << "\n";
  cout << "delay->Name() = " << delay->Name() << "\n\n";
  cout << "delay->isA() = " << delay->isA() << "\n\n"; // line 121
  delete delay;
}
  
[2.480]puma) g++-1.36.3 -v -o vhier vhier.cc
g++ version 1.36.3 (based on GCC 1.36.92)
 /usr/local/gnu/1.36.3/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 vhier.cc /usr/tmp/cca08929.cpp
GNU CPP version 1.36.92
 /usr/local/gnu/1.36.3/lib/gcc-cc1plus /usr/tmp/cca08929.cpp -quiet -dumpbase vhier.cc -version -o /usr/tmp/cca08929.s
GNU C++ version 1.36.3 (based on GCC 1.36.92) (68k, MIT syntax) compiled by GNU C version 1.36.92.
default target switches: -m68020 -mc68020 -m68881 -mbitfield
vhier.cc: In function int main ():
vhier.cc:121: Segmentation violation
g++-1.36.3: Program cc1plus got fatal signal 11.