Article View: gnu.g++.bug
Article #1319A bug in virtual functions.
From: Richard W. Kreutzer
Date: Mon, 04 Jan 1993 22:52
Date: Mon, 04 Jan 1993 22:52
53 lines
1406 bytes
1406 bytes
I believe the following exhibits a bug in g++:
================================== bug.cc =====================================
#include <iostream.h>
class Type {
public:
virtual void Print() = 0;
};
class Port : public Type {
public:
short flagBits;
#ifndef BUG
virtual void Print() = 0;
#endif
};
class PortOut : public ostream, public Port {
public:
PortOut(int fd) {init(new filebuf(fd));}
PortOut &operator<<(Type *p) {p->Print(); return *this;}
virtual void Print() {cout << "PortOut fn" << endl;}
};
PortOut& operator<<(PortOut& p, const Type &bt);
main() {
PortOut po(1);
Type *t = &po;
po << t;
}
=================================================================================
Compiled with:
g++ -g bug.cc -o bug
./bug
works correctly.
Compiled with:
g++ -DBUG -g bug.cc -o bug
./bug
dumps core.
If this is not a bug, could you let me know what I am doing wrong.
Thanks,
Dick
Technical Details
Message-ID:
<9301042252.AA29858@integra-yp>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!integra.UUCP!rwkShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!integra.UUCP!rwk From: rwk@integra.UUCP (Richard W. Kreutzer) Subject: A bug in virtual functions. Message-ID: <9301042252.AA29858@integra-yp> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 4 Jan 1993 22:52:47 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 54