home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / gcc / bug / 2771 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.3 KB  |  62 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!gte.com!steve%eowyn
  3. From: steve%eowyn@gte.com (Steve Preston)
  4. Subject: dtor call without ctor call on temp instance.
  5. Message-ID: <9211161929.AA02362@bunny.gte.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Mon, 16 Nov 1992 09:31:18 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 49
  12.  
  13. I tried mailing to bug-g++@prep.ai.mit.edu, but it bounced.
  14.  
  15. For gcc (g++) versions 2.2.2 and 2.3.1, on hppa1.1-hp-hpux and on
  16. decstation-ultrix.  
  17.  
  18. When a class has (1) an operator= method, (2) a constructor and 
  19. (3) destructor, calling the operator= method causes a destructor call
  20. on a temporary instance without a corresponding constructor call.
  21.  
  22. For example:
  23.  
  24. /* #include "String.h" */
  25.  
  26. /* String.h */
  27. const int max_string_length = 128; 
  28.  
  29. class String { 
  30.  public: 
  31.   String();
  32.   ~String();
  33.   
  34.   String operator=(const String &);
  35.   int length() const; 
  36.   int read (); 
  37.   void print() const; 
  38.   
  39.  private: 
  40.   char text[max_string_length+1]; 
  41. }; 
  42.  
  43. main(int, char *[])
  44. {
  45.   String s1, s2;
  46.   
  47.   s2 = s1;
  48.   
  49.   s1.print();
  50.   s2.print();
  51.   
  52.   return 0;
  53. }
  54.  
  55. After the assignment, the destructor is called on a temporary instance
  56. of String, without a corresponding constructor call.
  57.  
  58. I believe this is a bug.
  59. --
  60. Steve Preston (spreston@gte.com)
  61.  
  62.