home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / gnu / gcc / bug / 2116 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.5 KB  |  78 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!compuserve.COM!75030.631
  3. From: 75030.631@compuserve.COM (Gail Slemon)
  4. Subject: gcc optimization bug
  5. Message-ID: <920812163413_75030.631_CHG126-1@CompuServe.COM>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Wed, 12 Aug 1992 16:34:14 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 65
  12.  
  13. To: >Internet:bug-gcc@prep.ai.mit.edu
  14. Hi!
  15.     Found an optimizer bug and isolated it using
  16. the following code.  This was done on a Sun SPARC
  17. using gcc-2.2.2 and libg++-2.1.  The code works
  18. when compiling without the "O" or "O2" switches
  19. but does not work with optimization.  It seems
  20. that the non-virtual function, printa, is
  21. treated as a virtual function and the program
  22. does a core dump when a nil pointer tries to
  23. invoke the function.
  24. ---------------------
  25. #include <iostream.h>
  26. #define nil 0
  27.  
  28. class temp {
  29. public:
  30.     int a;
  31.     temp();
  32.     virtual void testa (temp*);
  33.  
  34.     void printa(ostream& os);
  35. };
  36.  
  37. temp::temp(){
  38.     a=0;
  39. }
  40.  
  41. void temp::testa(temp* tmp){
  42.     cout << tmp->a;
  43.     cout << "Survived test\n";
  44. }
  45.  
  46. void temp::printa(ostream& os){
  47.     os << "this is a test";
  48.  
  49.     if (this == nil) {
  50.         os << "This is nil\n";
  51.     }
  52.     else
  53.     {
  54.         this -> testa(this);
  55.         os << "This is not nil\n";
  56.     }
  57. }
  58.  
  59. main(){
  60.     temp aa;
  61.     temp* aptr = nil;
  62.  
  63.     aa.printa(cout);
  64.     aptr->printa(cout);
  65. }
  66. -----------------------
  67. Is there a way to be on your mailing list with
  68. my compuserve address?
  69.  
  70.      Thanks again!!!
  71.      Gail Slemon, Expersoft
  72.      phone #s: (619) 546-4100
  73.                (800) 755-7011
  74.  
  75.  
  76.  
  77.  
  78.