🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Steve Preston Mon, 16 Nov 1992 09:31
dtor call without ctor call on temp instance.
#1398
Author: Steve Preston
Date: Mon, 16 Nov 1992 09:31
48 lines
1431 bytes
I tried mailing to bug-g++@prep.ai.mit.edu, but it bounced.

For gcc (g++) versions 2.2.2 and 2.3.1, on hppa1.1-hp-hpux and on
decstation-ultrix.  

When a class has (1) an operator= method, (2) a constructor and 
(3) destructor, calling the operator= method causes a destructor call
on a temporary instance without a corresponding constructor call.

For example:

/* #include "String.h" */

/* String.h */
const int max_string_length = 128; 
 
class String { 
 public: 
  String();
  ~String();
  
  String operator=(const String &);
  int length() const; 
  int read (); 
  void print() const; 
  
 private: 
  char text[max_string_length+1]; 
}; 

main(int, char *[])
{
  String s1, s2;
  
  s2 = s1;
  
  s1.print();
  s2.print();
  
  return 0;
}

After the assignment, the destructor is called on a temporary instance
of String, without a corresponding constructor call.

I believe this is a bug.
--
Steve Preston (spreston@gte.com)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads