Bug 48282 - destructor called one too many times?
destructor called one too many times?
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.1
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-07-09 22:16 EDT by eeeg
Modified: 2010-06-14 10:18 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-06-14 10:18:25 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description eeeg 2001-07-09 22:16:14 EDT
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:
Comment 1 Matthew Miller 2007-04-10 15:07:02 EDT
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.
Comment 2 Denys Vlasenko 2008-07-31 11:05:51 EDT
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)

Note You need to log in before you can comment on or make changes to this bug.