From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010701 Description of problem: It seems (I'm know authority on the C++ standard) that the destructor is called one too many times when an object is passed by value to a function. When the user supplies their own copy constructor the destructor is called only twice (which is what I expect). The same behavior is seen with rh6.2,7.0,7.1 as well as gcc 3.0. The program in 'Steps to Reproduce' demonstrates this. How reproducible: Always Steps to Reproduce: > cat destruct.cc #include <iostream> using namespace std; class a { public: a() { cout << "Made an a." << '\n'; } ~a() { cout << "Destructor called." << '\n'; } #ifdef MY_CP_CON a(const a& rhs) { cout << "copy con called" << '\n'; } #endif }; void foo(a an_a) {} int main(void) { a my_a; foo(my_a); return 0; } > g++ -o destruct destruct.cc && ./destruct Made an a. Destructor called. Destructor called. Destructor called. > g++ -o destruct -DMY_CP_CON destruct.cc && ./destruct Made an a. copy con called Destructor called. Destructor called. Actual Results: Given in steps to reproduce. Expected Results: I'd expect 'g++ -o destruct destruct.cc && ./destruct' to produce: Made an a. Destructor called. Destructor called. Additional info:
I'm just going through and checking on old bugs -- if you still have interest, could you recheck against the latest Fedora Core release? Thanks.
does not happen with: # g++ -v Using built-in specs. Target: x86_64-redhat-linux ... gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC)