This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/16115] [3.5 regression] double-destruction problem with argument passing via temporary (breaks auto_ptr)
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Jun 2004 18:26:16 -0000
- Subject: [Bug tree-optimization/16115] [3.5 regression] double-destruction problem with argument passing via temporary (breaks auto_ptr)
- References: <20040621164318.16115.snyder@fnal.gov>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From bangerth at dealii dot org 2004-06-21 18:26 -------
Here's a reduced testcase:
---------------------
extern "C" void abort();
int count = 0;
struct T {
T() { count++; }
T(const T&) { count++; }
~T() { if (count==0) abort(); --count; }
};
struct auto_ptr {
T* p;
auto_ptr(T* __p) : p(__p) { }
~auto_ptr() { delete p; }
T* release() {
T* t = p;
p = 0;
return t;
}
};
void destroy (auto_ptr a) {
delete a.release();
}
int main ()
{
destroy (new T);
}
-----------------------------
For this, I get
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ x.cc -O2 && ./a.out
Aborted
We indeed call operator delete twice, once inside destroy, and once
inside the destructor of the argument to destroy. However, since release
sets p=0, the second time we call operator delete we shouldn't get a call
to the destructor of class T. Alas, we do, thus the abort.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Summary|[3.5 regression] problem |[3.5 regression] double-
|with argument passing via |destruction problem with
|temporary (breaks auto_ptr) |argument passing via
| |temporary (breaks auto_ptr)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16115