home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!cis.ohio-state.edu!compuserve.COM!75030.631
- From: 75030.631@compuserve.COM (Gail Slemon)
- Subject: gcc optimization bug
- Message-ID: <920812163413_75030.631_CHG126-1@CompuServe.COM>
- Sender: gnulists@ai.mit.edu
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Wed, 12 Aug 1992 16:34:14 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 65
-
- To: >Internet:bug-gcc@prep.ai.mit.edu
- Hi!
- Found an optimizer bug and isolated it using
- the following code. This was done on a Sun SPARC
- using gcc-2.2.2 and libg++-2.1. The code works
- when compiling without the "O" or "O2" switches
- but does not work with optimization. It seems
- that the non-virtual function, printa, is
- treated as a virtual function and the program
- does a core dump when a nil pointer tries to
- invoke the function.
- ---------------------
- #include <iostream.h>
- #define nil 0
-
- class temp {
- public:
- int a;
- temp();
- virtual void testa (temp*);
-
- void printa(ostream& os);
- };
-
- temp::temp(){
- a=0;
- }
-
- void temp::testa(temp* tmp){
- cout << tmp->a;
- cout << "Survived test\n";
- }
-
- void temp::printa(ostream& os){
- os << "this is a test";
-
- if (this == nil) {
- os << "This is nil\n";
- }
- else
- {
- this -> testa(this);
- os << "This is not nil\n";
- }
- }
-
- main(){
- temp aa;
- temp* aptr = nil;
-
- aa.printa(cout);
- aptr->printa(cout);
- }
- -----------------------
- Is there a way to be on your mailing list with
- my compuserve address?
-
- Thanks again!!!
- Gail Slemon, Expersoft
- phone #s: (619) 546-4100
- (800) 755-7011
-
-
-
-
-