vaughan%cadillac.cad.mcc.com@MCC.COM (Paul Vaughan) (01/12/90)
The following source compiles using g++-1.36.2.z, but produces incorrect
results.
#include <stream.h>
class NameSpaceTable;
class Object {
public:
Object() {};
virtual ~Object() {cout << "~Object()\n";}
};
class NamedObject: public Object
{
public:
NamedObject(const char* n = 0);
~NamedObject();
virtual const char* Name() const;
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";}
};
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";}
};
class IntegerAt : public Attribute {
public:
IntegerAt(const char* n=0,Entity* o=0,NameSpaceTable* nspace=0)
: Attribute(n,o,nspace) {};
// ~IntegerAt() {cout << "~IntegerAt()\n";}
};
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";}
};
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";}
};
class InterAtt : public AttributeBehavior {
public:
InterAtt() { cout << "InterAtt() Name() = " << Name() << "\n"; };
// ~InterAtt() {cout << "~InterAtt()\n";}
};
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() {};
};
class IServiceDelayAt : public InterAtt, public ServiceDelayAt {
public:
IServiceDelayAt();
~IServiceDelayAt();
// virtual const char* Name() const {
// cout << "<" << (int) this << " IServiceDelayAt::Name>";
// return ServiceDelayAt::Name();
// }
};
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";
delete delay;
}
[2.259]puma) g++-1.36.2.z -v -o vhier vhier.cc
g++ version 1.36.2 (based on GCC 1.36)
/usr/local/gnu/1.36.2/zlib/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/cca06269.cpp
GNU CPP version 1.36
/usr/local/gnu/1.36.2/zlib/gcc-cc1plus /usr/tmp/cca06269.cpp -quiet -dumpbase vhier.cc -version -o /usr/tmp/cca06269.s
GNU C++ version 1.36.2 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36.
default target switches: -m68020 -mc68020 -m68881 -mbitfield
/usr/local/gnu/1.36.2/zlib/gcc-as -mc68020 -o vhier.o /usr/tmp/cca06269.s
/usr/local/gnu/1.36.2/zlib/gcc-ld -o vhier -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o vhier.o -lg++ /usr/local/gnu/1.36.2/zlib/gcc-gnulib -lc
[2.260]puma) vhier
main()
Bus error
[2.261]puma)
Note that using g++-1.36.2.y, the compiler segv's in main on the "new"
line. This file is clearly related to some files I sent earlier
(which worked to some extent)--the only changes were making Entity a
virtual base class in Behavior and Attribute and removing the Name()
methods from IServiceDelayAt and ServiceDelayAt.